Variables in Python are dynamically typed, Meaning the datatype is inferred frm their assigned value.…

" />
Menu
×
×
   ❮   
PYTHON FOR DJANGO DJANGO FOR BEGINNERS DJANGO SPECIFICS PAYMENT INTEGRATION API BASICS Roadmap
     ❯   

VARIABLES & TYPES IN PYTHON

Variables & types home

×

Share this Topic

Share Via:

Thank you for sharing!


Variables are containers that can  hold data values. Variables in Python are dynamically typed, Meaning the datatype is inferred frm their assigned value.

Python has the following data types built-in by default, in these categories: 

  1. Text Type: str

  2. Numeric Types: int, float, complex

  3. Sequence Types: list, tuple, range

  4. Mapping Type: dict

  5. Set Types: set, frozenset

  6. Boolean Type: bool

  7. Binary Types: bytes, bytearray, memoryview

  8. None Type: NoneType

There is a function to check the datatype of a variable or data structure. the command is 

type(variable_name)
'''
  output:
    <class 'datatype'>
'''

It returns the class the variable belongs to. 

Why does this return a class?

In Python, Datatypes are implemented by using classes. so there are classes called int, str, float,complex and more. when we create a variable of a type, what we effectively are doing is creating an object of the class of the datatype. 

simple exercise: 

 

a = 12       #int
b = 12.42      #float
c = "Django tutorial"      #str

print("a: ",type(a))
print("b: ",type(b))
print("c: ",type(c))
'''
    output:
        a:  <class 'int'>
        b:  <class 'float'>
        c:  <class 'str'>

'''

Django-tutorial.dev is dedicated to providing beginner-friendly tutorials on Django development. Examples are simplified to enhance readability and ease of learning. Tutorials, references, and examples are continuously reviewed to ensure accuracy, but we cannot guarantee complete correctness of all content. By using Django-tutorial.dev, you agree to have read and accepted our terms of use , cookie policy and privacy policy.

© 2025 Django-tutorial.dev .All Rights Reserved.
Django-tutorial.dev is styled using Bootstrap 5.
And W3.CSS.