Data Types in Python

Data Types in Python

As we know Python is an object-oriented programming language so everything is considered as an object in Python, data types are actually classes and variables are instance (object) of these classes.
Depending upon the properties, there are manly 7 basic data types:
1. Numbers: This datatype mainly has a numerical value.

  • Integer
  • Float
  • Complex
a = 10
print(a, "is of type:", type(a))

b = 5.0
print(b, "is of type:", type(b))

c = 1 + 2j
print(c, "is of type:", type(c))

Output:
data type

2. String: String datatype in python can be written in single or double or triple-quotes. It is sequence of characters. It is immutable data type.

string = "Biochemithon"
print(string, "is of type:", 
      type(string))

Output:
datatype-1
3. List: List is a collection data type which is ordered and changeable i.e. mutable.

a = [1, 2.5, 'biochemithon']
print(a, "is of type:", 
      type(a))

Output:
datatype-2

4. Dictionary: Dictionary is a collection datatype like List but it is unordered, changeable and indexed. We have key-value pairs in the dictionary. We can use keys as indexes since they are unique but the value in the key can be duplicated. Mutable data type elements can’t be used as a keys in the dictionary.

a = {1: "python", 2: "biochemithon"}
print(a, "is of type:", 
      type(a))

Output:
datatype-3
5. Tuple: Tuple is a collection datatype which is ordered and unchangeable i.e. immutable.

a = (1, 2.5, 'biochemithon')
print(a, "is of type:", 
      type(a))

Output:
datatype-4
6. Set: Set is also a collection datatype but it is unordered and does not contain any duplicate values. It is mutable data type.

a = {50, 40, 30, 30, 10}
print(a, "is of type:", 
      type(a))

Output:
datatype-5

7. Boolean: This data type is either True or False. Boolean variables are defined by the True as well as False keywords. It is a immutable data type.

a = True
b = False
print(a, "is of type:", 
      type(a))

print(b, "is of type:", 
      type(b))

Output:
datatype-6

Leave a Reply

Your email address will not be published.

📢 Need further clarification or have any questions? Let's connect!

Connect 1:1 With Me: Schedule Call


If you have any doubts or would like to discuss anything related to this blog, feel free to reach out to me. I'm here to help! You can schedule a call by clicking on the above given link.
I'm looking forward to hearing from you and assisting you with any inquiries you may have. Your understanding and engagement are important to me!

This will close in 20 seconds