Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Tutorial
  3. Python Variables and Data Types

Core Python · Tutorial 3

Python Variables and Data Types

Understand variables, assignment, dynamic typing, and the core built-in types: str, int, float, bool, and None.

Open the compilerPractice exercises
beginner8 min readUpdated November 19, 20264 learning goals
On this page
  1. Dynamic typing
  2. Core built-in types
  3. Naming variables
  4. Multiple assignment
  5. Constants by convention
  6. Check your understanding

What you will learn

  • Create and reassign variables
  • Name variables using Python conventions
  • Inspect values with type()
  • Recognise str, int, float, bool, and None
Before this lesson: Python print() and Comments

A variable is a name that refers to a value. You create one with an assignment statement.

Python
name = "Ada"
age = 36
height = 1.68
is_engineer = True

The = sign is assignment, not mathematical equality. Read age = 36 as "age is assigned the value 36".

Dynamic typing#

Python is dynamically typed: a variable can refer to values of different types at different times.

Python
value = 10
print(type(value).__name__)   # int

value = "ten"
print(type(value).__name__)   # str

The object has a type; the name simply points at the object. This flexibility is convenient, but clear names and small functions help prevent mistakes.

Core built-in types#

| Type | Purpose | Examples | | --- | --- | --- | | str | Text | "hello", 'ILoveCompiler' | | int | Whole numbers | 0, 42, -7 | | float | Decimal numbers | 3.14, -0.5, 2.0 | | bool | Logical values | True, False | | NoneType | Absence of a value | None |

type(value) returns the type object. . __name__ gives its readable name:

Python
print(type(42))
print(type("Python"))
print(type(None))
Expected output

<class 'int'> <class 'str'> <class 'NoneType'>

The angle brackets are part of the representation printed by Python.

Naming variables#

Variable names may contain letters, digits, and underscores. They cannot start with a digit and cannot be a reserved keyword such as class or for.

Good names describe the value:

Python
student_count = 28
is_submitted = False
total_price = 49.95

Python style (PEP 8) uses snake_case for variables and functions, and CapWords for classes. Names are case-sensitive: total and Total are different variables.

Avoid shadowing built-ins

Names such as list, str, sum, and input are already used by Python. Reassigning them can break code that expects the built-in. Choose numbers instead of list, for example.

Multiple assignment#

Assign several variables at once, or give them the same value:

Python
x, y = 3, 8
a = b = 0

print(x, y, a, b)

Tuple assignment is especially useful for swapping values without a temporary variable:

Python
x, y = y, x
print(x, y)

Constants by convention#

Python has no enforced constants. A name written in uppercase signals that it should not change:

Python
MAX_ATTEMPTS = 3
SITE_NAME = "ILoveCompiler"

Check your understanding#

What are the types of these values?

Python
values = [12, "12", 12.0, True]
for value in values:
    print(value, type(value).__name__)

Run the program and check your answers in the output. Next, use numbers and operators to perform calculations.

Previous tutorialPython print() and CommentsNext tutorialPython Numbers and Arithmetic Operators

Related tutorials

beginner

Python Numbers and Arithmetic Operators

Work with integers and floats, use arithmetic operators, understand precedence, and avoid floating-point surprises.

9 min read
beginner

Python Type Conversion and Input Values

Convert between strings, integers, and floats safely, and understand which conversions can fail.

7 min read

On this page

  1. Dynamic typing
  2. Core built-in types
  3. Naming variables
  4. Multiple assignment
  5. Constants by convention
  6. Check your understanding

Run the examples

Every Python block has a Run in compiler button that opens the code in a new tab.