TutorialsPythonVariables and Data Types

Variables and Data Types

Python variables, numbers, strings, booleans — the building blocks of every script

Variables store data in Python. Unlike Excel cells (A1, B2) or SQL columns, Python variables have names you choose — and Python automatically detects what type of data you stored. Python has four basic data types you will use constantly in data work: • int — whole numbers (age, count, year) • float — decimal numbers (salary, percentage, price) • str — text (names, categories, labels) • bool — True or False (is_active, has_discount) Python is dynamically typed — you do not declare the type. Just assign a value and Python figures it out.

Syntax

variable_name = value   # assignment
type(variable_name)     # check the data type

Examples

Creating variables of each type
# Integer
total_orders = 1250
year = 2026

# Float
avg_salary = 65000.50
tax_rate = 0.18

# String
city = "Noida"
department = 'Data Analytics'

# Boolean
is_active = True
has_internship = False

# Check types
print(type(total_orders))   # <class 'int'>
print(type(avg_salary))     # <class 'float'>
print(type(city))           # <class 'str'>
print(type(is_active))      # <class 'bool'>
Type conversion — common in data cleaning
# Data often comes in as wrong types
salary_text = "75000"      # str from CSV
salary_num = int(salary_text)  # convert to int

price_text = "1299.99"
price_num = float(price_text)  # convert to float

count = 42
count_text = str(count)    # convert to string for labels

# Common in pandas data cleaning:
# df['Salary'] = df['Salary'].astype(int)
💡 Type conversion errors (ValueError) are one of the most common bugs in data cleaning scripts.

Key Points

  • Python variable names are case-sensitive: salary ≠ Salary
  • Use snake_case for variable names: total_sales, not totalSales
  • type() tells you what data type a variable holds
  • int() / float() / str() convert between types — essential for data cleaning
  • None is Python's equivalent of NULL in SQL or blank in Excel

Practice Question

What is the data type of the value 3.14 in Python?