Open links in new tab
  1. In Python, variables are used to store data values and are created when you first assign a value to them. Python is dynamically typed, meaning you don’t need to declare the type explicitly — it’s inferred from the assigned value.

    # Example: Different variable types
    age = 25 # Integer
    name = "Alice" # String
    height = 5.6 # Float
    is_student = True # Boolean

    print(age, name, height, is_student)
    Copied!

    This will output:

    25 Alice 5.6 True
    Copied!

    Creating Variables You simply use the = operator to assign a value:

    x = 10
    y = "Python"
    Copied!

    Variables can change type during execution:

    x = 42 # int
    x = "Now text" # str
    Copied!

    Multiple Assignments Python allows assigning values to multiple variables in one line:

    a, b, c = 1, 2.5, "Hello"
    p = q = r = 100 # same value to multiple variables
    Copied!

    Type Checking & Casting Use type() to check a variable’s type:

    print(type(a)) # <class 'int'>
    Copied!

    Convert between types using casting functions:

    num_str = "50"
    num_int = int(num_str)
    pi_str = str(3.14)
    Copied!

    Naming Rules

    Feedback
  2. Python Variables - GeeksforGeeks

    Mar 25, 2026 · In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that …

  3. Python Variables - Complete Guide

    Jul 23, 2024 · Learn about Python variables with detailed examples. Understand different types, including integers, floats, strings, and more. Master scope, type …

  4. Variables in Python: Usage and Best Practices

    In this tutorial, you'll learn how to use symbolic names called variables to refer to Python objects, and gain an understanding of how to effectively use these …

  5. Python Variables

    In this tutorial, you will learn about variables in Python language. You will learn how to create variables, initialize variables, reassign variables, get type of value in a variable, use variables in an expression, …

  6. Python Variables: A Beginner's Guide to Declaring, Assigning, and ...

    Variables in Python are objects. A variable is an object of a class based on the value it stores. Use the type () function to get the class name (type) of a variable. In the above example, num is an object of …

  7. People also ask
    Loading
    Unable to load answer
  8. Python Examples - Programiz

    This page contains examples of basic concepts of Python programming like loops, functions, native datatypes and so on.

  9. Python Variables: How to Define/Declare String Variable …

    Nov 10, 2025 · In this Python tutorial, we learn working with variable, declare, Re-declare, concatenate, local, global and delete variables.

  10. Variables in Python: Types, Rules, Examples

    Developers use variables in Python to interact with data and make programs robust and adaptable. This tutorial will explore Python variables, their rules, types, and more with the help of examples.

  11. Python Variables - NetworkLessons.com

    This lesson explains with examples how to declare Python variables for strings, numbers, functions, other variables, and more.