Загрузка...

🔁 Control Flow in Python

🔁 Control Flow in Python

Control flow decides which statements run and in what order based on conditions or loops.
1. Conditional Statements
➤ if
2. Looping Statements
➤ for loop
for i in range(5):
print(i)
➤ while loop
3. Loop Control Statements
➤ break
Stops the loop.
for i in range(10):
if i == 5:
break
➤ continue
Skips current iteration.
Python
for i in range(5):
if i == 2:
continue
print(i)
➤ pass
Does nothing (placeholder).
Python
if True:
pass
4. match Statement (Python 3.10+)

day = 3
match day:
case 1:
print("Monday")
case 2:
print("Tuesday")
case 3:
print("Wednesday")
case _:
print("Invalid day")
5. try-except (Exception Flow)
try:
x = int(input("Enter a number: "))
except ValueError:
print("Invalid input")
else:
print("You entered:", x)
finally:
print("Done")

Видео 🔁 Control Flow in Python канала Ravi Ranjan
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять