Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Can we change Python for loop range (higher limit) at runtime?
No, You can't modify a range once it is created. Instead what you can do is use a while loop instead. For example, if you have some code like:
for i in range(lower_limit, higher_limit, step_size):
# some code if i == 10: higher_limit = higher_limit + 5
You can change it to:
i = lower_limit while i < higher_limit: # some code if i == 10: higher_limit = higher_limit + 5 i += step_size
Advertisements
