Myvideo

Guest

Login

5 | Loops | Python for Complete Beginners

Uploaded By: Myvideo
6 views
0
0 votes
0

print(’ I am inside loops’) # while loop # while boolean_exp: # statements a = 4 b = 1 while b <= a: print(’ I am inside while loop ’) b = b 1 # 4 iterations # Sum of natural numbers n = 10 sum = 0 i = 1 while i <= n: sum = sum i i = i 1 print(’Sum is: ’, sum) # while loop with else # while loop can have an optional esle block # else is executed when cond in while is False i = 0 while i <= 3: print(’ I am inside loop ’) i = i 1 else: print(’ I am inside else ’) # for loop # for val in sequence: # statements numbers = range(1, 11) # range is used to create sequence of numbers sum = 0 for i in numbers: sum = sum i print(’ Sum is: ’, sum) # for with else numbers = range(1, 4) for i in numbers: print(’ inside for loop ’) else: print(’ inside else ’) ... #RaghavPal #Python_loop_tips_and_tricks #Looping_in_Python #Looping_techniques_in_Python #use_Python_for_loops_to_efficiently #Learn_how_to_loop_through_lists_in_Python 20230714 SyCCjfZxpXk

Share with your friends

Link:

Embed:

Video Size:

Custom size:

x

Add to Playlist:

Favorites
My Playlist
Watch Later