In programming languages, you will use some programming word when you would like to display a message.
- In Python that word is print. The easiest way we can output data in Python is using print function.
- Print is a function and that’s why we will be using parenthesis ( ) with print. Functions are explained in another lesson.
- Usually the value we would like to print is placed inside the parenthesis. If the value is a message then we place it inside double quotes. If it’s a variable then we don’t need to place it inside double quotes
Example of Python print:
1 |
print("This is a message using Python print function") |
In the above example, we are displaying a message using print function. Text messages are placed inside double quotes (“)
1 2 3 4 |
print("Print can show contents on screen in double quotes") print('Print can show contents on screen in single quotes') print('''Print can show contents on screen in triple single quotes''') print("""Print can show contents on screen in triple double quotes""") |
In the above example, we can see that print function can show messages using double quotes (“), single quote (‘), triple single quotes (”’) or triple double quotes (“””)
Example of Python print for variable:
1 2 |
x = "I am a variable of string data type" print(x) |
In the above example, we have used print function to show value of a variable named x.
Variables names are not placed inside double quotes. Variables and data types are explained in another lesson.
Example of Python print for multiple values:
1 2 3 |
x = "I am a variable of string data type" y = 23 print("Many different ways of using print function ", x, y " Try these yourself" ) |
In the above example, we have used one print function to show value of a variable and also string type message. variables and string are separated using a comma (,) in print function.