Functions, arguments and return values
A function is a named piece of functionality that a program can use. You have used several already: print, input, int, float, str and type. Using a function is called calling it: you write its name followed by parentheses.
The values inside the parentheses are the function's arguments, the data it works on. In print("Score:", score) the two arguments are "Score:" and the value of score. Some functions can be called with no arguments at all (print() prints an empty line), and some take several, separated by commas. In everyday talk, programmers often say parameter when they mean an argument. Strictly, a parameter is the name inside a function that receives an argument, a difference you'll see once you write functions of your own later in the course.
Return values
Many functions also give back a value, called their return value. When the call runs, Python puts the return value in its place, so a function call is an expression. input returns what the user typed, as a string, which is why you usually store it in a variable.
A new function shows this well. len returns the length of a string: the number of characters in it, with spaces and punctuation included.
sentence = input("Type a sentence: ")
print(f"That's {len(sentence)} characters.")
I like tea.Type a sentence: I like tea.
That's 11 characters.The letters make up 8 of the 11 characters; the two spaces and the period are the other 3. If the user presses Enter without typing anything, input returns the empty string "", a string with no characters at all, and its length is 0. Since len(...) gives an int, you can store it, calculate with it or compare it, like any other number:
name = input("Choose a username: ")
length = len(name)
if length < 5:
print(f"{name} has only {length} characters. Use at least 5.")
adaChoose a username: ada
ada has only 3 characters. Use at least 5.Calls inside calls
Since a call is an expression, it can be the argument of another call. You have done this since part 1: in int(input("Age: ")), Python first calls input, and its return value, a string, becomes the argument of int. The conversion functions int, float and str are functions like any other: each takes one argument and returns its value as another type.
Not every argument works with every function. len counts the characters of a string, but a number has no characters to count:
year = 2026
print(len(year))
Traceback (most recent call last):
File "main.py", line 2, in <module>
print(len(year))
~~~^^^^^^
TypeError: object of type 'int' has no len()The message says that a value of the type int has no length. Convert the number into a string first, and then count: len(str(year)) is 4, since str(year) is the string "2026".