Python

Important Statements

What is a Variable?

A variable is a name that refers to a value stored in the computer's memory. Think of it as a label or a box holding data.

Assigning Values to Variables

Use the assignment operator (=) to assign a value to a variable.

variable_name = value

Examples:

age = 30             # Assigning an integer
name = "Alice"       # Assigning a string
is_student = True    # Assigning a boolean
prices = [10, 20, 30] # Assigning a list

Variable Types

Python is dynamically typed, meaning you don't need to declare the variable type explicitly. The type is determined by the value assigned.

You can check the type of a variable using the type() function:

my_variable = 123
print(type(my_variable)) # Output: <class 'int'>

another_variable = "hello"
print(type(another_variable)) # Output: <class 'str'>

Reassigning Variables

You can change the value a variable refers to at any time.

count = 5
print(count) # Output: 5

count = 10 # Reassigning the variable
print(count) # Output: 10

Multiple Assignment