In Python, you can assign values to variables using the =
operator. Here's a basic example:
pythonx = 5
In this example, we're assigning the value 5
to the variable x
.
You can also assign values to multiple variables at once, like this:
pythonx, y, z = 1, 2, 3
In this example, we're assigning the value 1
to x
, 2
to y
, and 3
to z
.
You can also assign the same value to multiple variables at once, like this:
pythonx = y = z = 0
In this example, we're assigning the value 0
to all three variables, x
, y
, and z
.
You can also perform arithmetic operations during assignment, like this:
pythonx = 5
y = x + 2
In this example, we're assigning the value 5
to x
, and then assigning the value 7
to y
, which is x + 2
.
Note that in Python, variables are dynamically typed, which means that you don't need to declare the data type of a variable before assigning a value to it. The data type of a variable is automatically determined based on the type of value assigned to it.