![]() ![]() Python supports having an else statement associated with a loop statement. Here, we took the assistance of the len() built-in function, which provides the total number of elements in the tuple as well as the range() built-in function to give us the actual sequence to iterate over. ![]() ![]() When the above code is executed, it produces the following result − Now this list can be iterated using the for statement. To obtain a list object of the sequence, it is typecasted to list(). Range() generates an iterator to progress integers starting with 0 upto n-1. It generates an iterator of arithmetic progressions. The built-in function range() is the right function to iterate over a sequence of numbers. Each item in the list is assigned to iterating_var, and the statement(s) block is executed until the entire sequence is exhausted. ![]() Then, the first item in the sequence is assigned to the iterating variable iterating_var. If a sequence contains an expression list, it is evaluated first. The for statement in Python has the ability to iterate over the items of any sequence, such as a list or a string. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |