The first instruction you will most likely learn when using Python is the print() instruction. It is used to display/output a message on screen.
1 |
print("Hello World") |
Using Variables
The print command can be used to output the content of a variable:
1 2 3 |
username="admin" print("You are logged as:") print(username) |
Using String Concatenation
You can join multiple strings together (string concatenation using +) to print them on a single line:
1 2 |
username="admin" print("You are logged as:" + username) |
Casting numbers (e.g integers) into string and vice-versa:
You can convert (cast) a number (e.g integer) into a string using the str() function or convert/cast a string into an integer using the int() function:
1 2 |
score=10 print("Your score:" + str(score)) |