Python Data Types With Practical Examples

author
2 minutes, 21 seconds Read
Home » Tech Learning » Python » Python Data Types With Practical Examples

As we already saw python data types and it’s the definition, now we will see all data types with its practical example.

1. Numeric Data type:

We already knew the numeric data type used for storing numeric values, so let’s see an example of all 3 numeric data types as Integer, Float, and Complex. If you want to check which type of data type is in python you can use the type() function.

# Integer data type (# keyword is used to comment in python)
a = 10 
print(a) # print value of a.
print(type(a)) #type() function will identify the datatype
example of Integer datatype
# Float data type
 a = 40.34
 print(a)
 print(type(a))
example of float data type
# Complex data type
 a = 2+ 5j
 print(a)
 print(type(a))   
example of complex data type

2. Sequence type:

Advertisements

It is a collection of similar or different data types which include 3 more types like “String”, “List”, “Tuples”. Let’s see an example of all 3 data types:

#String data type
  str = 'Hello world, welcome to the single quote of string'
  str1 = "Hello world, welcome to double quote of string"
  str2 = """Hello world, welcome to triple quote of string"""         
example of string data type
# List data type [ ]
  list = [12, "Hello" ,"World",48]
  print(list)        
  print(type(list)) 
example of list data type
# Tuple data type ( )
   tuple = ("Hello", "Welcome" , "Python")
   print(tuple) 
   print(type(tuple)        
example of tuple data type

3. Set type:

As we already knew set is a collection of unordered data type which is mutable it means after creation it will be editable. Let’s see an example of the set type.

# Set data type { }
set1 = {'Alice',10,20,40,'welcome','python'} # Creating set with values
set4 = set() # Creating empty set
print(set1)
print(set4)
example of set data type

4. Mapping type:

Mapping type contains Dictionary data type which is represented as key: value pair form. it is enclosed with curly braces. You can access the value of a dictionary using the key directly and print it whenever it’s necessary. Let us see an example of dictionary data type

# Dictionary data type {key:value}
d = {1:"Tom",2:"Bob",3:"Alice"}
 print(d)
 {1: 'Tom', 2: 'Bob', 3: 'Alice'}
 print(type(d))
example of dictionary data type

5. Boolean type:

We already knew the definition of data type which represents True or False value based on the comparison. whenever you will compare two values then the expression is executed and it always returns the Boolean value which can be either True or False. Let us see an example of Boolean type

# Boolean data type
print(20>10)
 print(40<60) print(10>20)
example of Boolean data type

These are all the data types which is used in python. You can practice by installing python in your machine and execute all the basic data type programs.

If you found this article useful please provide your valuable feedback in the below comment box EduTaxTuber!

Similar Posts

Leave a Reply

England vs Senegal: FIFA World Cup 2022 No Curfew in Mumbai: Section 144 Imposed to ensure Peace Elon Musk suspends Kanye West Twitter Account for inciting violence Pak Vs England: England vs Pakistan FIFA World Cup 2022: CBDT Notifies Income Tax Exemption
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock