Обновить less3.md

This commit is contained in:
parent af32342af5
commit d5c71d6c7c
1 changed files with 35 additions and 21 deletions

View File

@ -1,6 +1,7 @@
Ссылка на урок: https://youtu.be/aFT0w1kMoFs?si=AQK2JgfOyKW5VzsW [Ссылка на урок](https://youtu.be/aFT0w1kMoFs?si=AQK2JgfOyKW5VzsW)
Операторы в Python ### Операторы в Python ###
```python
x = 11 x = 11
if x > 10: if x > 10:
x += 1 x += 1
@ -14,11 +15,11 @@ print(x)
if x == 1: if x == 1:
pass pass
# TODO допишем потом # TODO допишем потом
```
Циклы в Python ### Циклы в Python ###
#### while ####
while ```python
def cycle_while(): def cycle_while():
x = 1 x = 1
while x < 10: while x < 10:
@ -31,28 +32,33 @@ def cycle_while():
print(x) print(x)
else: else:
print("Сработает в любом случае") print("Сработает в любом случае")
```
for #### for ####
```python
def cycle_one(): def cycle_one():
my_list_1 = [1, 2, 3, 4, 5, 6, 7, 8] for i in my_list_1: my_list_1 = [1, 2, 3, 4, 5, 6, 7, 8]
for i in my_list_1:
print(i) print(i)
def cycle_two(): def cycle_two():
my_list_1 = ['Стул', 'Шкаф', 'Стол'] len_list = 0 my_list_1 = ['Стул', 'Шкаф', 'Стол']
len_list = 0
for product in my_list_1: for product in my_list_1:
len_list += len(product) len_list += len(product)
print(product) print(product)
print("Всего символов ", len_list) print("Всего символов ", len_list)
def cycle_break(): def cycle_break():
my_list_1 = [1, 2, 3, 4, 5, 6, 7, 8] for i in my_list_1: my_list_1 = [1, 2, 3, 4, 5, 6, 7, 8]
for i in my_list_1:
if i == 4: if i == 4:
print(i) print(i)
break break
def cycle_else(): def cycle_else():
my_list_1 = [1, 2, 3, 10, 4, 5, 6, 7, 8] for i in my_list_1: my_list_1 = [1, 2, 3, 10, 4, 5, 6, 7, 8]
for i in my_list_1:
if i == 10: if i == 10:
print(i) print(i)
break break
@ -61,13 +67,15 @@ def cycle_else():
print('Цикл завершен') print('Цикл завершен')
def cycle_continue(): def cycle_continue():
my_list = [1, 2, 3, 4, 5, 6, 7, 8] for i in my_list: my_list = [1, 2, 3, 4, 5, 6, 7, 8]
for i in my_list:
if i == 2: if i == 2:
continue continue
print(i) print(i)
```
Распаковка в Python ### Распаковка в Python ###
```python
def cycle_rasp_1(): def cycle_rasp_1():
""" """
ВсеЭлементы = Новый Массив; ВсеЭлементы = Новый Массив;
@ -91,16 +99,20 @@ def cycle_rasp_1():
КонецЦикла; КонецЦикла;
""" """
elements = [(1, 1), (2, 2)] for element in elements: elements = [(1, 1), (2, 2)]
x, y = element[0], element[1] print(x + y) for element in elements:
x, y = element[0], element[1]
print(x + y)
def cycle_rasp_2(): def cycle_rasp_2():
elements = [(1, 2), (3, 4)] for element in elements: elements = [(1, 2), (3, 4)]
for element in elements:
x, y = element x, y = element
print(x + y) print(x + y)
def cycle_rasp_3(): def cycle_rasp_3():
elements = [(2, 3), (4, 5)] for x, y in elements: elements = [(2, 3), (4, 5)]
for x, y in elements:
print(x + y) print(x + y)
# Распаковка с автонумерацией # Распаковка с автонумерацией
@ -115,7 +127,8 @@ def cycle_rasp_enumerate():
Сообщить(Строка(Счетчик) + " " + Мебель[Счетчик]); Сообщить(Строка(Счетчик) + " " + Мебель[Счетчик]);
КонецЦикла; КонецЦикла;
""" """
my_list_1 = ['Стул', 'Шкаф', 'Стол'] for i, product in enumerate(my_list_1): my_list_1 = ['Стул', 'Шкаф', 'Стол']
for i, product in enumerate(my_list_1):
print(i, product) print(i, product)
def cycle_range_1(): def cycle_range_1():
@ -181,5 +194,6 @@ def cycle_dict_2():
print(price) print(price)
total_price += price total_price += price
print("Общая сумма товаров", total_price) print("Общая сумма товаров", total_price)
```
[Назад на главную](readme.md) [Назад на главную](readme.md)