/* */ Click to Join Live Class with Shankar sir Call 9798158723

Python data types ?

In python we do not required to define data type of variable. it automatically define types of variable according to data enter into variable. In C ,C++, JAVA we need to define types of variable.
Like :
int a; float b; char c; etc.
This is called statically defined data types or programming language.
But in python,
No need to define type just
a= 4
b= 4.5
c= "c"
this is called dynamically define data types or programming language.

Note:- If you want to see type of variable in python use type(variable name) function.

Data types

  • The data types define the types of data stored in a memory location.
  • Data types specify how we enter data into our programs and what type of data we enter.


The None type

The None datatype represents an object that does not contain any value. In languages like Java it is called null object but in python it is called None object. In python program maximum of only one None object is provided.

int data type

The int data type represents an integer number. An integer number is a number without any decimal point or fraction part.
Example :
a= 34 b= -24
Here, a and b is called int type variable since it hold integer value i.e 34 and -24

Note:- there is no limit for the size of an int data type it can store very large integer numbers

float data types

The float data type represents floating point number . It contain a decimal point.

0.4, -5.4534, 380 that is called floating point number
Here, p is called floating point data type variable since it hold floating value i.e 3.14.

Complex data types

A complex number is a number that is written in the form of a+bi
Here, a is represents the real part of the number and b represents the imaginary part of the number the suffix j or J after b indicates the square root value of -1 the part a and b may contain integers or floats value.

for example :
6+3j are called complex number.

# Python program to add two complex numbers:-
Output :

bool data types

The bool datatype in python represents boolenan values. There are only two boolean values True or False that can be represented by this datatypes python internally represents True as 1 and False as 0. A blank string like “ ” is also represented as false condition will be evaluated internally to either true or false.

A python program
c= a<b
print(c) -->True will be output
True+True= will display 2 #true is 1 and false is 0
True-false= will display 1

Str data types

In python str represents string datatype. A string is represented by a group of characters. Strings are enclosed in single quotes or double quotes both are valid.
str=“shineskill” # str is a string type variable that are store shineskill as a value.
str ='shineskill' #same as first

Note :
=> If we want to store multiple line string to store in a variable we have to use “””(triple double quotes) or "‟‟(triple single quotes)
str1=“”” shineskill
.....online class “””
str2="‟‟ this is computer
.....this is laptop‟‟‟
The bytes data types represents a group of byte numbers just like an array does.
A byte number is any positive integer form 0 to 255 (inclusive).
Bytes array can store numbers in the range from 0 to 255 and it cannot even store negative numbers.

Example :
elements=[20, 0, 30, 34, 23] #this is a list of byte numbers
x= bytes(elements) #convert the list into bytes array
print(x[0]) # display 0th element i.e 20

Bytes array we can not modify or edit any element in the bytes
Example :
x[0]=34 gives an error. We are trying to replace 0th element 20 by 34 which is not allowed.

bytearray data types

the bytearray datatype is similar to bytes datatype. The difference is that the bytes type array cannot be modified but bytearray type array can be modified . It means any element or all the elements of the bytearray type can be modified.

Example :

elements=[20, 0, 30, 34, 23] #this is a list of byte numbers.
x= bytearray(elements) #convert the list into bytearray.
print(x[0]) # display 0th element i.e 20
=> We can modify or edit the element of bytearray.
x[0]=50 # replace 20 by 50.

list data type

List in python are similar to array in c or java. A list represents a group of elements. The main difference between a list in python or array in c or c++ java is that.

=> A list can store different types of elements but an array can store only one type of elements.
=> Also lists can grow dynamically in memory. But the size of array is fixed and they cannot grow at runtime.
=> List are represented using square brackets[] and the elements are written in [] separated but commas.

Example :
list = [10, 20, -23, 24,-45, „raj‟, „rajesh‟]
Will create a list with different types of elements the slicing operation like [0: 3]
Represents elements from 0th to 2nd positions i.e 10 and 20

tuple datatype

A tuple is similar to a list. A tuple contains a group of elements which can be of different types. The elements in the tuple are separated by commas and enclosed in parentheses (). Whereas the list elements can be modified it is not possible to modify the tuple elements. That means a tuple can be treated as a red only list.

Example :

The individual elements of the tuple can be referenced using square braces as tp[0], tp[1] new if we try to modify the 0th element as
This will give error.

range datatype

The range datatype represents a sequence of numbers. The numbers in the range are not modifiable. Generally range is used for repeating a for loop for a specific number of time to repeat a range of number we can simply write
Here, the range object are created with the numbers starting from 0 to 9 we can display these numbers using a for loop as:-
For i in r:print(i)
The above statement will display number from 0 to 9 we can use a starting number an ending number and a step value in the range object as
This will create a range object with a starting number 10 and an ending number 20 and the step size is 2 it means the numbers in the range will increate by 2 every time so the for loop.
For I in r:print(i) # will display 10 12 14 ,…18

set datatype

a set is an unordered collection of elements much like a set in mathematics. The order of elements is not maintained in the sets. It means the elements may not appears in the same order as they are entered into the set moreover a set does not accept duplicate elements.

There are two sub types of sets : => Set datatype
=> Frozenset datatype

Set datatype
To create a set we should enter the elements separated by commas inside curly braces{ }
s={10, 20, 30 ,20, 5, 6}
Set s is not maintaining the order of the elements. We entered the elements in the order 10 20 30 20 and 40 but it is showing another order.
Also we repeated the element 20 in the set but it has stored only one 20. we can use the set () function to create a set as :-
Example :
ch = set(hellow)
print(ch) # display as {"h‟,‟e‟,‟l‟,‟o‟,‟w‟}

Remove function can be use to remove a particular value from a set
s.remove(20) #dispaly 10 20 30 5 6

Update method can be add elements to a set

frozenset datatype

The frozenset datatype is same as the set datatype . The main difference is that the elements in the set datatype can be modified whereas the elements of frozenset cannot be modified we can create a frozenet by passing a set to frozenset() function

Example :
print(s) # may display {50,60,90}
fs=frozenset(s) #create frozenset s
print(fs) # it may display frozenset({50,60,90})

Note:- Here, update and remove method will not work on frozensets since they cannot be modifiy or update.

Mapping in Python

A map represents a group of elements in the form of key value pairs so that when the key is given we an retrieve the value associated with it. The dict datatype is an example for a map. The dict represents a dictionary that contains pairs of elements such that the first element represents the key and the next one comes its value.
The key and its value should be separated by a colon ( : ) and every pair should be separated by comma all the elements should be enclosed inside curly brackets {}

d= {10: "raj", 11: "palak"}
Here, d is a name of dictionary and 10 is a key and its associated value is raj
Also, we can create a empty dictionary

Sequence in python

We can perform various operation on dictionary. To retrieve value upon giving the key we can simply mention d[key].
To retrive only keys from the dictionary we can use the method keys() and to get only values we can use the method values()

We can also update the value of key as d[key]= newvalue
We can delete a key and corresponding value using del module
Example :
Del d(11)
Will delete from directory

Type() function

Type() function is use to print type of variable or data types

a = 20
output :
<class "int">

b = True
output :
<class "bool‟>


We can convert integer number into the following : binary of 65 is (1000001)2
octal of 65 is (101)8
Hexa of 65 is (41)16

Python provide in-built functions for base conversions.
we can use bin() function to convert decimal to binary format.
Example :-

we can use oct() function to convert from any base to octal format.
Example :-
>>>oct(65) "o0101"