Data Types in python

Data Types in python

Hey techies, I hope and wish u have a good day today, welcome to this week's article. Today, I am going to make you gain knowledge on "Data types in python". Hope you are loving my articles and I appreciate it if you show a response by commenting, liking or even sharing on your socials.

I am focusing more on Python so I also suggest you to read my previous articles on Python.

1.) What is meant by data types?

Variables can hold values, and every value has a data type. Python is a dynamically typed language; hence we do not need to define the type of the variable while declaring it.

EX: int,float,string...etc

2.) How to know about the data type we have?

Python has made easy for us to check the type of data using keyword "type()".

EX: type(variable_u_have_assigned_here)

x = 90
print(type(x))

y = 20.4
print(type(y))

z = "The journey of two wings"
print(type(z))

Output:
<class 'int'>
<class 'float'>
<class 'str'>

3.) Standard data types

A variable can hold different types of values. EX: a person's name must be stored as a string, whereas its id must be stored as an integer.

Python provides various standard data types that define the storage method on each of them. The data types defined in Python are given below.

  1. Numbers

  2. Sequence Type

  3. Boolean

  4. Set

  5. Dictionary

4.) Numeric

Number stores numeric values. The integer, float, and complex values belong to a Python Numbers data-type. Python provides the "type()" function to know the data-type of the variable.

NOTE: isinstance()

isinstance() is a keyword used to check whether the data type belongs to its particular data or not.

here it needs two arguments to be passed (variable , int|float|complex) based on data u gave it will return True or False

x = 2580
print(type(x))                       #type

y = 130.4
print(type(y))

z = 2+3j
print(type(z))

print(isinstance(x,int))            #need  two varaible for isinstance(1,2)
print(isinstance(y,float))
print(isinstance(z,complex))

Output:
<class 'int'>
<class 'float'>
<class 'complex'>
True
True
True

5.) Some basic knowledge on numerics

  • Python supports three types of numeric data.

  • Int - Integer value can be any length such as integers 100, 2, 29, -20, -150 etc. Python has no restriction on the length of an integer. Its value belongs to integer(int).

  • Float - Float is used to store floating-point numbers like 1.9, 9.902, 15.2, etc. It is accurate upto 15 decimal points.

  • complex - A complex number contains an ordered pair, i.e., x + iy where x and y denote the real and imaginary parts, respectively. The complex numbers like 2.14j, 2.0 + 2.3j, etc.

"Be there for others , but never leave yourself behind"

"Lets meet in the next concept until then cyaaa"

Did you find this article valuable?

Support Smd Sohail by becoming a sponsor. Any amount is appreciated!