A variable is a named container used to store data. In Python, you don’t need to declare the type of variable — it’s inferred automatically:
x = 5
name = "Alice"
pi = 3.14_myVar ≠ MyVar)# Valid:
name = "John"
_age = 30
user1 = "Admin"
# Invalid:
1name = "Error"
user-name = "Error"Python allows variables to change type dynamically:
x = 42 # int
x = "hello" # now a stringUse type() to check the type, and int(), str(), float() to convert:
x = 5
print(type(x)) # <class 'int'>
x = str(5)
y = float(3)a, b, c = "Apple", "Banana", "Cherry"
x = y = z = 0user_name over xfor i in range(5))What will be the output of the following code?
Hint: What type does Python assign to a after reassignment?
Ask the AI if you need help understanding or want to dive deeper in any topic