Python For GCSE
Variables & Assignment
In programs, variables are words used to represent stored information. This might be information that has been gathered from a user with input statements, read from a file, or a calculation carried out in the program.
In Python, variables are created when we first assign a value to them.
a = 5 b = 6.3 c = a + b d = "Hello World" print(a) print(b) print(c) print(d)
If we save this code in a blank file and run the program, we see,
When we make a variable, Python works out the data type of the variable from the context. In the above program, the variable a has the type integer. It is a whole number. The variables b and c are of the type float, real numbers (number with decimal places). The variable d is a string. It stores text. Notice that we had to use quotation marks when writing the text we wanted to store.
One thing to remember is that Python is case sensitive. This applies to all of its statements and any variables. Upper and lower case names are considered to be different.