Python - For Loop with Examples - Python Programming Tutorial - APPFICIAL

Опубликовано: 28 Сентябрь 2021
на канале: Appficial
724
5

A for loop executes a code block for each element in a container. A container is typically a list, tuple or a string.

Example for looping through a list of names:

for name in [‘Kanye’, ‘Jay’, ‘Beyonce’]:
print(f’Hello {name}!')

When you iterate over a dictionary using a for loop, it assigns the loop variable with the keys of the dictionary. The values are then accessed using the dictionary name followed by the key inside square brackets.

When you iterative over a string, you are looping through each character in the string

str = ’’
for character in ”I love underscores.":
str += character + '_’
print(str)

To loop backwards, use the reversed() function which reverses the order of element

Subscribe to Appficial for more programming videos coming soon. Also, don't forget to click LIKE and comment on the video if it helped you out!


На этой странице сайта вы можете посмотреть видео онлайн Python - For Loop with Examples - Python Programming Tutorial - APPFICIAL длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Appficial 28 Сентябрь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 724 раз и оно понравилось 5 зрителям. Приятного просмотра!