Understanding Variables in Python

In Python, variables play a crucial role in storing and manipulating data. They act as containers that hold values. In this article, we’lll be discussing about the fundamentals of variables in Python.

What are Variables?

Variables are names assigned to data values in Python. They act as placeholders, allowing us to refer to the data by its assigned name. Think of variables as labeled boxes where you can store different types of information.

Variable Naming Conventions and Rules

Python has specific rules and conventions for naming variables. Following these guidelines ensures code clarity and maintainability. Here are some key points to remember:

Variable names can contain letters, numbers, and underscores (_), but they must start with a letter or an underscore.
Variable names are case-sensitive, meaning “myVar” and “myvar” are treated as different variables.
Avoid using reserved words (keywords) as variable names, such as if, while, or def.
Choose meaningful and descriptive names to enhance code readability.

Assigning Values to Variables

To assign a value to a variable, we use the assignment operator (=). Here’s an example:

myVariable = 42

In the above example, we assigned the value 42 to the variable “myVariable”.


Variable Reassignment and Updating Values

In Python, variables can be reassigned with new values. This means you can change the value of a variable after it has been assigned.

Here’s an example:

x = 10
x = x + 5

In the above example, we initially set x to 10, and then we reassign it by adding 5 to its existing value. The final value of x becomes 15.

Variable Scope

Variables in Python have scope, which defines their visibility and accessibility within different parts of the code. The scope determines where a variable can be accessed and modified.

The two main types of variable scope in Python are:

  • Global scope: Variables defined outside of any function or class have global scope and can be accessed from anywhere in the code.
  • Local scope: Variables defined within a function or block have local scope and can only be accessed within that specific scope.
    Understanding variable scope is crucial for writing maintainable and bug-free code.



Variables are essential building blocks in Python programming. They allow us to store, manipulate, and retrieve data. By understanding variable naming conventions, assignment, reassignment, and scope, you’ll be equipped to write more robust and readable Python code.


Learn how to work with Python and SQL Server – Enroll to our course!

Enroll to our online course “Working with Python on Windows and SQL Server Databases” with an exclusive discount, and get started with Python data access programming for SQL Server databases, fast and easy!

By the time you complete the course:

  • You will know how to install Python on Windows and set your development environment with Visual Studio Code and the proper extensions
  • You will know how to connect your Python programs to SQL Server instances and databases
  • You will know how to run different types of T-SQL queries against your SQL Server databases, from within your Python Programs
    • Execute and process SELECT, INSERT, UPDATE and DELETE T-SQL statements
    • Call Dynamic Management Views (DMVs)
    • Call aggregation functions
    • Call SQL Server global system variables
  • You will know how to execute SQL Server functions and stored procedures, from within your Python Programs
  • You will know how to use parameters and exception handling for all the above database operations within your Python code
Working with Python on Windows and SQL Server Databases - Online Course
(Lifetime access, downloadable resources, course completion certificate and more!)

Enroll to the Course


Recommended Online Courses:


Read Also:


Reference: {essentialDevTips.com} (https://www.essentialdevtips.com/)

© essentialDevTips.com

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)