A variable is a name that points to a value. It's the first concept every Python programmer learns — and getting the details right early saves hours of confusion later.
In Python you create a variable simply by assigning a value with = : age = 12. No type declaration needed — Python figures out the type from the value, and you can reassign any variable to any type at any time.
Assignment creates the variable — there is no separate declaration step like in C or Java.
name = "Ada" # a string age = 12 # an integer height = 1.52 # a float is_coder = True # a boolean print(name, age) # Ada 12
Names can contain letters, digits and underscores, but can't start with a digit and can't be a reserved word (if, for, class…). Python convention is snake_case for variables.
user_name = "ok" # good: snake_case userName = "works" # allowed but not Pythonic _hidden = "ok" # leading underscore = internal by convention # 2cool = "no" # SyntaxError: can't start with a digit # for = 5 # SyntaxError: reserved word
A Python variable is just a label — it can point to a value of any type, and be re-pointed freely. Check the current type with type().
x = 10 print(type(x)) # <class 'int'> x = "ten" # perfectly legal reassignment print(type(x)) # <class 'str'>
Python lets you assign several variables in one line — and swap values without a temporary variable, a trick that surprises programmers coming from other languages.
a, b, c = 1, 2, 3 # unpack in one line x = y = z = 0 # same value to all three a, b = b, a # swap! no temp variable needed print(a, b) # 2 1
Python has no true constants — the convention is ALL_CAPS names to signal "do not change me".
PI = 3.14159 MAX_PLAYERS = 4 SITE_NAME = "BitWithBite" # Nothing stops reassignment — the caps are a promise between programmers.
NameError: name 'x' is not defined — assignment must come first= assigns, == compares. Writing if x = 5: is a SyntaxErrorlist, str or print silently breaks those functions for the rest of your programNo. Python is dynamically typed — the type comes from the value you assign, and you can check it anytime with type(x).
Technically nothing — Python has no enforced constants. By convention, ALL_CAPS names like MAX_SIZE tell other programmers not to reassign them.
Yes. age, Age and AGE are three different variables.
Yes — a leading underscore conventionally marks it as internal/private, and double leading underscores trigger name mangling inside classes.