Learn Python - 5 [print, printing]
We already have seen print
in previous posts. Now I want to focus on printing functionality. If you are a beginner it's a way to know your program really does what you want.
print()
is a function and print whatever you pass to this function as a parameter. You can pass multiple parameters to the print()
function.
>>> print(45)
45
>>> print('Hello Jamie')
Hello
>>> print(1, True, 'Steem')
1 True Steem
As you see multiple parameters can be any type.
Now lets print variables values with print()
:
>>> name = 'Joe'
>>> print('Hello my name is', name)
Hello my name is Joe
>>> age = 29
>>> print(name, 'is', age, 'old')
Joe is 29 old
We can also concatenate strings with +
while printing them:
>>> print('a' + 'b' + 'c' + 'd')
abcd
But for numbers it's different, it adds two numbers:
>>> print(4 + 5)
9