Latest posts

10/recent/ticker-posts

Data Types in Python | Identify the Data tyeps in Python

 Data Types in Python

What are the Data Types?

Data types in Python specify the type of a variable or the type of value that a variable holds.
Data types play an important role in Python because they determine how a value can be used or manipulated.
For example, you can perform mathematical operations such as addition and subtraction on integers, not strings. 

Additionally, different data types have different methods and properties that can be used on them.
It's worth noting that Python is a dynamically-typed language, which means that the data type of a variable can change at runtime.
Data types in Python are used to define the kind of data that can be stored in a variable and specify how the data can be used or manipulated.

Understanding data types ensures that data is collected in the preferred format and that the value of each property is as expected.

There are several built-in data types in Python, including:

  1. integers (int)
  2. floating-point numbers (float)
  3. strings (str)
  4. booleans (bool)
  5. lists (list)
  6. tuples (tuple)
  7. sets (set)
  8. dictionaries (dict)
  9. and others such as complex numbers (complex), bytes (bytes), bytearrays (bytearray), etc.

Python Data Types are distributed as follows:

  1. Numeric data types: int, float, complex.
  2. Sequence types: string, list, tuple.
  3. Boolean type: bool
  4. Mapping data type: dict.
  5. Binary types: bytes, bytearray.
  6. Set data types: set, frozenset.

How to Identify Data Types?

You can identify the data type of any object by using the type() function.

Here we can see some examples of type() function.

 x = "Hello World"
 print(type(x))
 //Output
 <class 'str'>

 x = 5
 print(type(x))
 //Output
 <class 'int'>

 x = 2.3
 print(type(x))
 //Output
<class 'float'>

 x = [3, 5, 7]
 print(type(x))
 //Output
<class 'list'>

 x = {"name : "viraj", 
      "age" : 19}
 print(type(x))
 //Output
 <class 'dict'>


Explaining each data type of Python in a single article is very complex, In the upcoming tutorial we can going to deep into the each Data Type of Python...




Also Visit


Post a Comment

0 Comments