Python Variables and Data Types

Python 8 min min read Updated: Mar 09, 2026 Beginner
Python Variables and Data Types
Beginner Topic 4 of 10

Variables & Data Types in Python

In any programming language, variables are used to store data that can be used later in a program. Python provides a simple and flexible way to create variables without explicitly declaring their data type. This makes Python very beginner-friendly and easy to use.

In this tutorial, we will understand how variables work in Python and explore the different types of data that Python supports.

What is a Variable in Python?

A variable is a container used to store data in memory. Each variable has a name and holds a value that can be used or modified during program execution.

In Python, you do not need to specify the data type while declaring a variable. Python automatically detects the type of data based on the assigned value.

python name = "John" age = 25 height = 5.9 print(name) print(age) print(height)

In the example above, three variables are created: name, age, and height. Python automatically assigns the appropriate data type to each variable.

Rules for Naming Variables

When creating variables in Python, you must follow certain naming rules:

  • Variable names must start with a letter or underscore.
  • Variable names cannot start with a number.
  • Variable names can contain letters, numbers, and underscores.
  • Variable names are case sensitive.
  • Reserved keywords such as if, for, and class cannot be used as variable names.

Example:

python user_name = "Alice" total_score = 95 studentAge = 20

Multiple Variable Assignment

Python allows assigning values to multiple variables in a single line.

python x, y, z = 10, 20, 30 print(x) print(y) print(z)

You can also assign the same value to multiple variables.

python a = b = c = 100 print(a) print(b) print(c)

What are Data Types in Python?

Data types define the type of data stored in a variable. Python supports several built-in data types that allow developers to work with numbers, text, collections, and logical values.

Some of the most commonly used Python data types include:

  • Numeric Types (int, float, complex)
  • String
  • Boolean
  • List
  • Tuple
  • Set
  • Dictionary

Numeric Data Types

Python supports three main numeric data types.

Integer (int)

Integers represent whole numbers without decimal points.

python age = 30 year = 2026 print(age) print(year)

Float

Float represents numbers with decimal points.

python price = 99.99 temperature = 36.5 print(price) print(temperature)

Complex

Complex numbers contain a real and imaginary part.

python num = 3 + 5j print(num)

String Data Type

A string represents textual data in Python. Strings can be written using single quotes or double quotes.

python name = "Python Programming" message = 'Welcome to Edugators' print(name) print(message)

Strings support many operations such as concatenation, slicing, and formatting.

Boolean Data Type

Boolean values represent logical states: True or False. They are commonly used in conditional statements.

python is_student = True is_logged_in = False print(is_student) print(is_logged_in)

List Data Type

A list is a collection of items stored in a specific order. Lists are mutable, which means their values can be changed.

python fruits = ["apple", "banana", "mango"] print(fruits) print(fruits[0])

Tuple Data Type

A tuple is similar to a list but cannot be modified after creation.

python coordinates = (10, 20) print(coordinates)

Set Data Type

A set is a collection of unique elements and does not allow duplicate values.

python numbers = {1, 2, 3, 4} print(numbers)

Dictionary Data Type

A dictionary stores data in key-value pairs. It is useful for storing structured data.

python student = { "name": "John", "age": 21, "course": "Python" } print(student["name"])

Checking Data Type

You can use the type() function to check the data type of a variable.

python x = 10 print(type(x)) name = "Python" print(type(name))

Best Practices for Variables

  • Use meaningful variable names.
  • Follow the snake_case naming convention.
  • Avoid using single-letter variable names.
  • Keep variable names descriptive.

Conclusion

Variables and data types are the foundation of Python programming. Variables allow us to store information, while data types define the type of data that can be stored. Understanding these concepts helps programmers write efficient and well-structured Python programs.

In the next tutorial, we will explore Python Operators and learn how Python performs mathematical and logical operations.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators