-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlesson10.py
More file actions
42 lines (37 loc) · 1.22 KB
/
lesson10.py
File metadata and controls
42 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Функции
def helloWorld():
print("Hello, World!")
helloWorld()
helloWorld()
# Функция с параметрами
def printMax(a,b):
if a>b:
print(a, 'больше', b)
elif a==b:
print(a, 'равно', b)
else:
print(a, 'меньше', b)
printMax(7,9)
printMax(7,5)
printMax(7,7)
# Функция с параметрами по умолчанию
# def sayHello(name="Ivan", age) так не правильно
def people(age, name="Ivan"):
print("Имя: {1}, Возраст: {0}".format(age, name))
people(25, "Evgen")
people(18)
# Возврат значения из функции и передача нескольких параметров в виде массива
def total(*numbers):
total = numbers[0]
for n in numbers:
if n > total:
total = n
return total
print("Максимальный из аргументов:", total(5,4,1,0,9,17,3,2,15,4,2))
# Возврат нескольких значений в виде кортежа
def get_two_param():
return (2, "Text Param")
print(get_two_param())
# exec и eval
exec('print("Выполняется код из строки")')
print('Вычисляется выражение из строки (2+5)*2: ', eval('(2+5)*2'))