We can use the print statement to output a result:
Python
print("Hello World")
Output
Hello World
The Python interpreter can be used as a calculator:
print(5+5/2)
7.5
Variables are containers for storing data values.
We can store data into variables for example:
weight = 60
To do anything useful with data, we need to assign its value to a variable. In Python, we can assign a value to a variable, using the equals sign ‘=’. For example, to assign value ’60’ to a variable ‘weight’, we would execute:
From now on, whenever we use weight, Python will substitute the value we assigned to it. In layman’s terms, a variable is a name for a value.
In Python, variable names:
To display the value of a variable to the screen in Python, we can use the print function:
print(weight)
60
Moreover, we can do arithmetic with variables right inside the print function:
print(2.2 * weight)
132.0
Comments start with a #, and Python will render the rest of the line as a comment:
#This is a comment.print("Hello, World!")
Comments can remind you what functions do or allow you to stop lines of code from running