Functions Flashcards

1
Q

Keyword Arguments

A

def say_hi(name, greeting):
print(f”{greeting} {name}”)

say_hi(“John”, “Hello”)
say_hi(name=”Anna”, greeting=”Hi”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Return Values

A

def sum_two_numbers(number_1, number_2):
return number_1 + number_2

result = sum_two_numbers(7, 8)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The global Statement

A

Если внутри функции нужно изменить глобальный аргумент, то нужно использовать global утверждение.

def spam():
global eggs
eggs = ‘spam’

eggs = ‘global’
spam()
print(eggs)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Lambda Functions

A

В Python, lambda функции это single-line, anonymous функция, которая может иметь любое кол-во аргументов, но может иметь только одно выражение.

add = lambda x, y: x + y
add(5, 3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly