Table of Contents
1. What Are Variables in Python? 2. Variable Assignment and Naming Rules 3. Dynamic Typing and Data Types 4. Variable Scope (Local, Global, Nonlocal) 5. Best Practices for Naming Variables 6. Memory Management and Object References 7. Free Resources & Internships (2026)1. What Are Variables in Python?
At its core, a variable in programming is essentially a reserved memory location to store values. In other words, a variable in a Python program gives data to the computer for processing. However, Python handles variables differently than many other statically-typed languages like C++ or Java.
In Python, variables are better thought of as names or labels attached to objects in memory, rather than boxes where you put data. When you assign a value to a variable, Python creates an object in memory and binds the variable name to that object.
"In Python, variables are not buckets containing values; they are labels pointing to objects." - Luciano Ramalho, Fluent Python
2. Variable Assignment and Naming Rules
Assigning a value to a variable in Python is straightforward. You do not need to declare the variable type beforehand. You simply use the assignment operator =.
# Simple assignment
name = "Skilloratic"
age = 5
is_learning = True
# Multiple assignment in a single line
x, y, z = 10, 20, 30
# Assigning the same value to multiple variables
a = b = c = 100
When naming variables, Python enforces a few strict rules and suggests several conventions:
- Must start with a letter or underscore:
user_ageor_private_varare valid.1st_placeis invalid. - Can only contain alphanumeric characters and underscores: (A-z, 0-9, and _). No special characters like
@,$, or%are allowed. - Case-sensitive:
Age,age, andAGEare three distinct variables. - Cannot be a Python keyword: You cannot name a variable
class,def,return,if, etc.
3. Dynamic Typing and Data Types
Python is a dynamically typed language. This means you do not need to explicitly declare the data type of a variable. The Python interpreter automatically infers the data type based on the assigned value at runtime.
Furthermore, the type of a variable can change during the execution of a program if you reassign it to a different type of value. This flexibility makes Python incredibly fast to write but requires developers to be mindful of what their variables currently hold.
# Dynamic typing in action
my_variable = 100 # Initially an integer (int)
print(type(my_variable)) # Output: <class 'int'>
my_variable = "Hello" # Now a string (str)
print(type(my_variable)) # Output: <class 'str'>
my_variable = [1, 2, 3] # Now a list
print(type(my_variable)) # Output: <class 'list'>
mypy catch bugs early. Example: age: int = 25.
4. Variable Scope (Local, Global, Nonlocal)
The scope of a variable defines the region of the code where the variable is accessible. Understanding scope is crucial to avoid bugs related to unexpected variable modifications.
Local Scope
Variables declared inside a function are in the local scope. They cannot be accessed from outside that function.
def greet():
message = "Hello, World!" # Local variable
print(message)
greet()
# print(message) # This would raise a NameError
Global Scope
Variables declared outside of any function have a global scope and can be accessed anywhere in the file. If you need to modify a global variable inside a function, you must use the global keyword.
counter = 0 # Global variable
def increment():
global counter
counter += 1
print(counter)
increment() # Output: 1
Nonlocal Scope
Used in nested functions, the nonlocal keyword allows you to modify a variable in the nearest enclosing scope that is not global.
def outer_function():
x = "local"
def inner_function():
nonlocal x
x = "nonlocal"
print("Inner:", x)
inner_function()
print("Outer:", x)
outer_function()
# Output:
# Inner: nonlocal
# Outer: nonlocal
5. Best Practices for Naming Variables
Writing code that a machine can understand is easy; writing code that humans can understand takes discipline. Adhering to Python's style guide (PEP 8) ensures your code is professional and readable.
- Use snake_case for standard variables and functions: E.g.,
user_account_balanceinstead ofuserAccountBalance. - Be descriptive but concise: A variable named
employee_salaryis infinitely better thansoremp_sal. - Use UPPERCASE_WITH_UNDERSCORES for constants: Variables whose values should never change (like configuration values) should be capitalized. E.g.,
MAX_RETRIES = 5. - Prefix "private" variables with an underscore: E.g.,
_internal_state. This is a convention to tell other developers, "This is for internal use only, tread carefully."
6. Memory Management and Object References
Because variables are just labels, when you assign one variable to another, they both point to the exact same object in memory. This is particularly important when dealing with mutable objects like lists or dictionaries.
# Immutable objects (integers, strings, tuples)
a = 10
b = a
a = 20
print(b) # Output: 10 (b still points to the original integer 10)
# Mutable objects (lists, dicts, sets)
list_x = [1, 2, 3]
list_y = list_x
list_x.append(4)
print(list_y) # Output: [1, 2, 3, 4]
# Both labels point to the same list in memory!
To check if two variables point to the exact same memory location, you can use the is operator or compare their id() values.
7. Free Resources & Internships (2026)
To help you continue your Python journey, we have compiled a list of excellent free resources, bootcamps, and internship opportunities for 2026.
Free Learning Resources
- Official Python Tutorial: The most authoritative source for learning Python syntax and standards.
- Automate the Boring Stuff: A highly recommended free book for absolute beginners looking for practical projects.
- freeCodeCamp Python Certification: A comprehensive, project-based curriculum that is completely free.
- Developer Roadmaps: Excellent visual guides for navigating the broader backend ecosystem.
Python Internship Platforms
- Forage Virtual Work Experiences: Free virtual internships from top companies like JP Morgan, Citi, and EA. Highly recommended for resume building.
- Internshala (Global): Constantly updated listings for remote and on-site Python developer internships.
- Wellfound (formerly AngelList): The best place to find early-stage startup internships where Python is often the primary backend language.
Industry References & Sources
Claims regarding popularity, career demand, and salary expectations for Python developers are backed by the following official reports.
- Industry Trends: StackOverflow Developer Survey
- Salary Insights: Glassdoor Developer Salaries
- Market Demand: U.S. Bureau of Labor Statistics (BLS)
Python Variables Essential Resources
Ready to take the next step? Here are the most relevant and targeted resources specifically for Python Variables: