HTML CSS JAVASCRIPT PYTHON JAVA

Python Variables

Variables in Python are used to store data values. Unlike many other programming languages, Python does not require you to declare the type of a variable. The type is automatically determined when you assign a value.

Creating Variables

In Python, a variable is created the moment you assign a value to it using the equals (=) sign.

Example
x = 5
y = "John"

print(x)
print(y)
Try this code

Variable Types

Python variables can store different types of data such as numbers and text.

Example
x = 10        # integer
y = 3.14      # float
name = "Ali"  # string

print(x)
print(y)
print(name)
Try this code

Assigning Multiple Variables

You can assign values to multiple variables in one line.

Example
x, y, z = 1, 2, 3

print(x)
print(y)
print(z)
Try this code

Assigning Same Value

You can assign the same value to multiple variables in one line.

Example
a = b = c = 10

print(a)
print(b)
print(c)
Try this code

Variable Naming Rules

Best Practices

Using Variables in Output

You can combine variables to display complete information.

Example
name = "Ali"
age = 25

print("Name:", name)
print("Age:", age)
Try this code