Python Glossary Русский

all Python 3Functionsterm

Parameters and arguments

parameters

Parameters are the names in the function definition. Arguments are the values at the call site. Positional ones are passed in order, keyword ones by name.

Syntax

def f(a, b): ...
f(1, 2)  # позиционные
f(a=1, b=2)  # ключевые

Positional arguments must all come before keyword ones: f(a=1, 2) is a SyntaxError, not a runtime error. Conversely, parameter names are part of the function's contract — a keyword call breaks if you later rename the parameter.

Examples

def sub(a, b):
    return a - b
print(sub(10, 3))  # → 7
print(sub(b=3, a=10))  # → 7 (ключевые)
def full_name(first, last):
    return first + ' ' + last
print(full_name('Ivan', 'Petrov'))  # → Ivan Petrov
print(full_name(last='Petrov', first='Ivan'))  # → Ivan Petrov
def power(base, exp):
    return base ** exp
print(power(2, 8))  # → 256
print(power(exp=3, base=2))  # → 8
def greet(name, punct='!'):
    return 'Hello, ' + name + punct
print(greet('Bob'))  # → Hello, Bob!

See also

Open in the full glossarydocs.python.orgReport an inaccuracy