Datatype represents the type of data stored into a variable or memory.
Type of Data type :-
1.Built-in Data type
2.User Defined Data type
Built-in Datatype
These datatypes are provided by Python Language.
Following are the built-in data type:-
1.None Type
2.Numeric Types
3.Sequences
4.Sets
5.Mappings
User Defined Data type
1.Array
2.Class
3.Module
None Type
None datatype represents an object that doesn’t contain any value.
Numeric Type / Number
Following are the Numeric Data type:-
1.Int
2.Float
3.Complex
# Python Numbers | |
# Integers, floating point numbers and complex numbers falls under Python numbers category. They are defined as int, float and complex class in Python. | |
# We can use the type() function to know which class a variable or a value belongs to | |
# The isinstance() function to check if an object belongs to a particular class. | |
a = 5 | |
print(a, "is of type", type(a)) | |
a = 2.0 | |
print(a, "is of type", type(a)) | |
a = 1+2j | |
print(a, "is complex number?", isinstance(1+2j,complex)) | |
# Integers can be of any length, it is only limited by the memory available. | |
# A floating point number is accurate up to 15 decimal places. Integer and floating points are separated by decimal points. 1 is integer, 1.0 is floating point number. | |
# Complex numbers are written in the form, x + yj, where x is the real part and y is the imaginary part. Here are some examples. | |
>>> a = 1234567890123456789 | |
>>> a | |
1234567890123456789 | |
>>> b = 0.1234567890123456789 | |
>>> b | |
0.12345678901234568 | |
>>> c = 1+2j | |
>>> c | |
(1+2j) | |
Python List | |
List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type. | |
a = [5,10,15,20,25,30,35,40] | |
# a[2] = 15 | |
print("a[2] = ", a[2]) | |
# a[0:3] = [5, 10, 15] | |
print("a[0:3] = ", a[0:3]) | |
# a[5:] = [30, 35, 40] | |
print("a[5:] = ", a[5:]) | |
# Python Tuple | |
# Tuple is an ordered sequence of items same as list.The only difference is that tuples are immutable. Tuples once created cannot be modified. | |
t = (5,'program', 1+3j) | |
# t[1] = 'program' | |
print("t[1] = ", t[1]) | |
# t[0:3] = (5, 'program', (1+3j)) | |
print("t[0:3] = ", t[0:3]) | |
# Generates error | |
# Tuples are immutable | |
t[0] = 10 | |
Python Strings | |
String is sequence of Unicode characters. We can use single quotes or double quotes to represent strings. Multi-line strings can be denoted using triple quotes, ''' or """. | |
s = 'Hello world!' | |
print("s = ", s) | |
# s[4] = 'o' | |
print("s[4] = ", s[4]) | |
# s[6:11] = 'world' | |
print("s[6:11] = ", s[6:11]) | |
# Generates error | |
# Strings are immutable in Python | |
s[5] ='d' | |
Python Set | |
Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { }. Items in a set are not ordered. | |
a = {5,2,3,1,4} | |
# printing set variable | |
print("a = ", a) | |
# data type of variable a | |
print(type(a)) | |
# Python Dictionary | |
# Dictionary is an unordered collection of key-value pairs. | |
d = {1:'value','key':2} | |
print(type(d)) | |
print("d[1] = ", d[1]); | |
print("d['key'] = ", d['key']); | |
# Generates error | |
print("d[2] = ", d[2]); | |
# Conversion between data types | |
We can convert between different data types by using different type conversion functions like int(), float(), str() etc. | |
float(5) | |
int(10.6) | |
float('2.5') | |
str(25) | |
int('1p') | |
set([1,2,3]) | |
tuple({5,6,7}) | |
list('hello') | |
dict([[1,2],[3,4]]) | |
dict([(3,26),(4,44)]) |
# Literal is a raw data given in a variable or constant | |
#Integer Literal | |
a = 0b1010 #Binary Literals | |
b = 100 #Decimal Literal | |
c = 0o310 #Octal Literal | |
d = 0x12c #Hexadecimal Literal | |
#Float Literal | |
float_1 = 10.5 | |
float_2 = 1.5e2 | |
#Complex Literal | |
x = 3.14j | |
print(a, b, c, d) | |
print(float_1, float_2) | |
print(x, x.imag, x.real) | |
# When we print the variables, all the literals are converted into decimal values | |
# A string literal is a sequence of characters surrounded by quotes. We can use both single, double or triple quotes for a string. | |
strings = "This is Python" | |
char = "C" | |
multiline_str = """This is a multiline string with more than one line code.""" | |
unicode = u"\u00dcnic\u00f6de" | |
raw_str = r"raw \n string" | |
print(strings) | |
print(char) | |
print(multiline_str) | |
print(unicode) | |
print(raw_str) | |
# A Boolean literal can have any of the two values: True or False. | |
x = (1 == True) | |
y = (1 == False) | |
a = True + 4 | |
b = False + 10 | |
print("x is", x) | |
print("y is", y) | |
print("a:", a) | |
print("b:", b) | |
# Boolean literals | |
# A Boolean literal can have any of the two values: True or False. | |
x = (1 == True) | |
y = (1 == False) | |
a = True + 4 | |
b = False + 10 | |
print("x is", x) | |
print("y is", y) | |
print("a:", a) | |
print("b:", b) |




I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND