Python Variables and Literals

1. Declaring and Assigning Variables

# Variable assignment
count = 10
price = 99.99
name = "Python"

print(count)   # Output: 10
print(price)   # Output: 99.99
print(name)    # Output: Python

Variables in Python are dynamically typed and do not require explicit type declaration.


2. Multiple Variable Assignment

a, b, c = 1, 2, 3

print(a)  # Output: 1
print(b)  # Output: 2
print(c)  # Output: 3

This allows simultaneous assignment in a single statement.


3. Reassigning Variables

Python variables can reference different data types at different times.


4. Numeric Literals

Supports integer, floating-point, and complex number literals.


5. String Literals

String literals can be defined using single, double, or triple quotes.


6. Boolean Literals

Boolean literals are True and False (case-sensitive).


7. Special Literal: None

None represents the absence of a value.


8. Collection Literals

Python supports literal syntax for all major built-in collections.


9. Binary, Octal, and Hexadecimal Literals

Numeric literals can be expressed in different number systems.


10. Using Variables in Expressions

Variables participate directly in arithmetic and logical expressions.


Last updated