How to use Variables in Python3?
Published on Aug. 22, 2023, 12:15 p.m.
To use variables in Python3, you simply assign a value to a variable name using the equals sign =. Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. Here’s an example:
x = 5
y = 'Hello, World!'
z = True
In this example, we define three variables: x with a value of 5, y with a value of 'Hello, World!', and z with a value of True. Python automatically determines the data type based on the value assigned to the variable.
You can also perform operations on variables and use them in expressions:
x = 10
y = 3
z = x + y
print(z) # output: 13
In this example, we add the values of x and y and store the result in z. Then, we print the value of z.