Input and output#
(Click here for the German version of this page)
Output#
Just like with other programming languages, the input and output using a terminal are essential. At least regarding programs in the context of simple scripts.
To print something to the terminal in Python, one can use the function print()
.
name = "Joe Generic"
print(name)
# --> "Joe Generic"
The print()
function can also take multiple parameters. In this case, the provided parameters are concatenated with a whitespace between them.
name1 = "Joe Generic"
name2 = "John Doe"
print(name1, "is friends with", name2)
# --> "Joe Generic is friends with John Doe"
After a call to the print()
function, a line break is automatically created.
The following lines:
print(1)
print(2)
print(3)
result in the following output:
1
2
3
instead of
123
Input#
How users can provide input to a Python program through the terminal will not be discussed in this introduction.
If one wants to test the function foo(x)
, then one can for the time being just hard-code a given value for x
.
x = 5
foo(x)
# or just
foo(x)
For those, who are interested, here is the Python Referenz, with information regarding built-in Python functions such as input()
.
Alternatively, you can just search for it on the web with a search engine of your choice.