Python input and output
getting user input and showing (calculated) output
2025-11-03 12:19
// updated 2025-11-06 20:57
// updated 2025-11-06 20:57
In Python, getting user input and showing output are relatively simple built-in functions:
- input(text)
- print(text)
Python input
The argument of the built-in input function prompts the user with a command or question:
input('Please enter your name')We could also store this input inside a variable to use later:
name = input('Please enter your name')Notice how we don't need to use a keyword like "let" (in JavaScript, for example) to declare variables!
Python output
Although not called output, the built-in function for outputting text is a straightforward print:
print('Hi, ', name, '!')As in the above, if we use a variable, we must separate the strings with commas and take into account any whitespace!
Python string interpolation
To lessen the amount of commas and quotation marks, we can place an "f" at the start of the argument and wrap each variable name with {curly} braces:
print(f'Hi, {name}!')