logo CBCE Skill INDIA

Welcome to CBCE Skill INDIA. An ISO 9001:2015 Certified Autonomous Body | Best Quality Computer and Skills Training Provider Organization. Established Under Indian Trust Act 1882, Govt. of India. Identity No. - IV-190200628, and registered under NITI Aayog Govt. of India. Identity No. - WB/2023/0344555. Also registered under Ministry of Micro, Small & Medium Enterprises - MSME (Govt. of India). Registration Number - UDYAM-WB-06-0031863

What is data type in Python?


Data Type in Python
 

In Python, a data type is a classification that specifies which type of value a variable can hold. It defines the operations that can be performed on the data and the way the data is stored in memory. Python is a dynamically-typed language, which means that the data type of a variable is interpreted at runtime based on the type of value it holds.

 

Here are some common data types in Python:

 

  1. Numeric Types:

    • int: Integer type, e.g., 1, -5, 100.
    • float: Floating-point type, e.g., 3.14, -0.5, 2.0.
  2. Sequence Types:

    • str: String type, e.g., "hello", 'world'.
    • list: List type, e.g., [1, 2, 3], ['apple', 'banana'].
  3. Boolean Type:

    • bool: Boolean type, either True or False.
  4. Set Types:

    • set: Unordered collection of unique elements, e.g., {1, 2, 3}.
  5. Mapping Type:

    • dict: Dictionary type, e.g., {'key': 'value', 'name': 'John'}.
  6. None Type:

    • NoneType: Represents the absence of a value or a null value.
  7. Other Types:

    • complex: Complex number type, e.g., 2 + 3j.
    • bytes: Immutable sequence of bytes, e.g., b'hello'.

Python is designed to be flexible with types, and variables can change their types dynamically during execution. For example, a variable initially assigned an integer value can later be assigned a string or any other type of value.

x = 5         # x is of type int
x = "hello"   # x is now of type str

 

Understanding and using appropriate data types is crucial for writing efficient and bug-free Python code.

 

Thank you.


Give us your feedback!

Your email address will not be published. Required fields are marked *
0 Comments Write Comment