- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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