Data Types in Python

Hello friends, Here we will be going to discuss the Data Types in Python. If you missed the previous article on the Python tutorial, please check them once. We have mentioned the URLs at the end of the Post.

What’s inside:
Types Of DATA Types
Numeric Data Types in Python
Boolean
Sequence Type
Set
Dictionary
FAQs

Types Of DATA Types:

There are five types of Data types in python.Thye are –

data types in python
  • Numeric
  • Boolean
  • Sequence Type
  • Set
  • Dictionary

Numeric Data Types in Python

Like other languages, Python also has numeric data types in which numeric values are stored. A numeric value can be an Integer type, float type, or a complex number.

Integer: An integer in Python is denoted by int class. It can be a positive, negative, or whole number. In Python, there is no limit to the size or length of an integer value.

Float: It is represented by float class. This is a real number with a floating-point representation, in which a decimal symbol denotes a fractional point.

Example: b = 5.01

Complex Numbers – A complex class denotes the Complex number. It is specified as X(real part) +Y (imaginary part)j, where X and Y can be integer or float.

 Example : 4+3j
  • You can check the type of the value by using type() command. For example:
a = 56
print("Type of a: ", type(a)) 
  
b = 5.01
print("\nType of b: ", type(b)) 
  
c = 4 + 4j
print("\nType of c: ", type(c)) 
data types in python

Boolean

Boolean has the same function as other programming languages. It has one of two possible values, either True or False. The class bool represents this. Point to be noted that True and False are not similar to the true and false there are differences of capital and F. Python will throw an error if you use the small letter one.

Example:
print(type(True)) 
print(type(False)) 
  
print(type(true)) 
data types in python
You cam see that the difference of Capital T and F in the given output.

Sequence Type

The sequence is nothing but the ordered collection of similar or different data types. In Python, Sequence type is three types:

  • List
  • Tuple
  • String

List: Python Lists are similar to arrays. It is an ordered sequence of values. Lists are very flexible as the values in a list do not need to be of the same types.

For declaring a python list, we use comma(,) and by placing the sequence inside the square brackets[]Like:

X = [1, 3.2, 'python']

Tuple: Tuples is also an ordered Sequence of items. It is similar to List, and there is only one difference between List and Tuples that tuples can not be modified after it is created.

It is represented within parentheses ( ) where all items are separated by comma(,) usually a tuple is faster then lists.

For example:

t = (6,'tuple program', 1+3j)
Output of the above mentioned code

Strings: String is a sequence of Unicode character,ters or the string is a collection of one or more characters placed in a single quote(”), double-quote(” “), or triple quote. For representing the strings, We can use single quotes or double-quotes. The Multi-line strings can be referred to using triple quotes,'” or” “. It is denoted by str class.

For Instance:

my_string = 'Hello!!!'
print(my_string)

my_string = "Hello wrold!!"
print(my_string)

my_string = '''Hello!!'''
print(my_string)

# triple quotes string can be extended to multiple lines
:
my_string = """Hello, This is 1st string 
              example in Python"""
print(my_string)
data types in python
Output of the above mentioned in the example.

Set Data types in Python:

Python Set is an unordered collection of items that is unique. Set is denoted by the values separated by a comma inside the curly braces { }.

For instance:

a = {5,2,3,1,4}

Dictionary data types in Python

Python Dictionary is nothing but an unordered collection of data values. Generally, It is used for a huge amount of data. Dictionaries are optimized for retrieving the data. We have must know the key to retrieve the data.

In Python, dictionaries are defined in between curly braces {} with each item being a pair in the form of key: value. The Key and values of the dictionary can be of any type.

d = {3:'value','key':4}
print(type(d))

Output:

FAQs

Is x, y = 5, 6 a valid statement? True or False.
True
Equivalent operation for function pow(x, y) is __.
x ** y
What is the correct statement that assigns X as an infinite number?
X= float(‘inf’)

Recommended Posts:


In the above, we have discussed the basic data types in Python. In the forthcoming article, we will present the different variables in Python. If you have any difficulty or questions related to this topic or previous topics, then please feel free to contact us.

Thank you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *