2.1.4.4 Variables - data-shaped boxes
Using variables
You're allowed to use as many variable declarations as you need to achieve your goal, like this:
var = 1
account_balance = 1000.0
client_name = 'John Doe'
print(var, account_balance, client_name)
print(var)
You're not allowed to use a variable which doesn't exist, though (in other words, a variable that was not given a value).
This example will cause an error:
var = 1
print(Var)
We've tried to use a variable named
Var
, which doesn't have any value (note: var
and Var
are different entities, and have nothing in common as far as Python's concerned).
REMEMBER
You can use the
print()
statement and combine text and variables using the +
operator to output strings and variables, e.g.:var = "3.7.1"
print("Python version: " + var)
Can you guess the output of the snippet above?
Comments
Post a Comment