➢ Data Types in Python:
The purpose of datatypes in python is to ‘store the inputs of program in Main Memory i.e. RAM
of the computer by allocating sufficient of memory space’.
In Python, we have 14 different data types classified into 6 categories.
1. Fundamental Category Data Type:
a. Int
b. Float
c. Bool
d. Complex
2. Sequence Category Data-Type:
a. Str
b. Bytes
c. Bytearray
d. Range
3. List Category Data Type:
a. List
b. Tuple
4. Set Category Data Type:
a. Set
b. Frozenset
5. Dict Category Data Type:
a. Dict
6. None Type Category Data Type:
a. NoneType
➢ Fundamental Category Data Types:
1. Int
‘int’ is one of the pre-defined classes and it is treated as Fundamental Type.
The purpose of int in to ‘store Integer Data OR Literals OR Whole Numbers OR Integral
Values’.
Examples: sno, acno, empno, adcno, etc.
With int we can also store different number system values:
a. Decimal Number System: The decimal number system, also known as the base-10
system, is the most common numeral system used by humans. In the decimal system,
numbers are represented using 10 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
Base 10: The name "base-10" comes from the fact that each digit's value is multiplied by
powers of 10, based on its position. For example:
In the number 1234, the digit 4 represents
4×10^0=4
The digit 3 represents
3×10^1=30
The digit 2 represents
2×10^2=200
And the digit 1 represents
1×10^3=1000
When you add these together, you get
1000+200+30+4=1234.
b. Binary Number System: The binary number system, also known as the base-2 system, is
a numeral system that uses only two symbols: 0 and 1. It's the fundamental numeral
system used in computing and digital electronics because it aligns well with the on/off
behavior of electronic switches.
In the binary number 1011, the rightmost digit (1) represents
1×2^0=1
1×2^1=2
0×2^2=0
1×2^3=8
1+2+0+8=11
c. Octal Number System: The octal number system, also known as the base-8 system, is a
numeral system that uses eight symbols: 0, 1, 2, 3, 4, 5, 6, and 7. Octal numbers are
commonly used in computer programming, particularly in older systems, as they provide
a compact representation of binary data.
In the octal number 723, the rightmost digit (3) represents
3×8^0=3
2×8^1=16
7×8^2=448
3+16+448=467
d. Hexa-Decimal Number System: The hexadecimal number system, also known as the
base-16 system, is a numeral system that uses sixteen symbols: 0-9 and A-F. Hexadecimal
numbers are widely used in computing, particularly in programming and digital
electronics, because they provide a compact and human-readable representation of
binary data.
In the hexadecimal number 2A3, the rightmost digit (3) represents
3×16^0=3
10×16^1=160
2×16^2=512
3+160+512=675
Base Conversion Functions:
No Keyword should be used as variable in python. Class names can be taken as variable
names.
2. Float Data Type:
Float is one of the pre-defined classes and treated as Fundamental Data Type.
The purpose of float data type is to store real constant values or Floating Pointing values.
It stores the floating-point values in scientific notation.
The general format of scientific notation is that “Mantisa e Exponent”.
Normal Floating-Point Value = Mantisa into 10 raised to the power of exponent
The advantage of scientific notation is to take minimal storage of large volume normal
floating-point values.
It doesn’t allow us to use binary, octal and hexa-decimal values to directly store in
In Python, the ^ symbol is the bitwise XOR (exclusive OR) operator. It performs the XOR
operation on two numbers, bitwise.
If both bits are the same, the result is 0.
If the bits are different, the result is 1.
3. Bool Data Type:
'bool' is one of the pre-defined classes and treated as fundamental data type.
The purpose of bool data type is to 'store True, False Logical Values'.
In python, True and False are the keyword.
Internally in python programming, True is considered a 1 and False is considered as 0.
On the values of Bool Values, we can perform arithmetic operations.
Literals Objects Class
Literals are nothing but values that will be stored in objects.
Objects are used to store Literals.
Class is used to create the objects.
Error 1: Syntax Error
Error 2: Not Defined
Error 3: ZeroDevisionError
4. Complex Data Types:
'complex' is one of the pre-defined classes and treated as fundamental data type.
The purpose of this data type is to 'store Complex Values'.
The general notation of complex values is 'a +bj' where 'j=sqrt(-1) '.
Internally Real and Imaginary Parts are treated as Float Data Type.
To Get real and imaginary parts of a complex number, we need to define attributes.
➢ Sequence Category Data Types:
The purpose of sequence category data types is that to store sequence of values in a single
object.
1. str:
A string is a collection of numeric, alpha-numeric, characters and special-characters enclosed
in single or double quotes.
In Python, we have two types of str data.
a. Single Line String Data
b. Multi-Line String Data
Double and Single quotes can be used only to store single line only, multi-line data can’t be
stored using these.
We can use triple-double quotes or triple-single quotes to do so. Using that, we get the
continuity symbol. We can also use these to store single line string data.
When we store data in double quotes at the backend the data is stored in single quotes only
to save the maximum of memory space.
Memory-Management in str data: Consider the following statement execution to
understand.
Positive Indexing: Forward Direction Indexing. "0" to "len(strobj) -1"
Python also give Negative Indexing. This is also a Forward Direction Indexing. "len(strobj) " to
"-1".
Operations on str data: We can perform two types of operation.
a. Indexing Operation:
The process of obtaining one value/char at a time from StrObject by passing valid index
is called indexing.
Syntax: StrObj[index]
Here index can be positive or negative.
When we enter invalid index, we get Index Error.
b. Slicing Operation:
The process of obtaining Range of Values or Sub String from Main StrObj is called slicing
operation.
We can use it with 5 Syntaxes.
a. Strobj[Begin:End] : This syntax generates or obtains range of values from Begin to
End-1.
Begin < End → True → Some Values
Begin > End → False → ''
Begin = End → False → ''
b. Strobj[Begin:] : In this syntax, we are only specifying only beginning. End index is not
written and default taken as last character.
c. Strobj[:End] : In this index begging is by default taken as the first character.
d. Strobj[:]
By Using all the above 4 syntaxes, we are obtaining range of chars in forward
direction with default step as +1.
e. Strobj[Begin:End:Step]
Step here represent the change in character while moving in any direction. By
default, it was +1 previously.
Rule 1: Here Begin, End and Step can be either positive or negative.
Rule 2: If the value of step is positive then PVM takes the range of chars from begin
index to end-1 index in forward direction provided begin < end or we get space ('').
Rule 3: If the value of step is negative, then PVM takes the range of chars from begin
to end+1 in backward direction provided begin > end.
Rule 4: In forward direction, if we specify 0 as end index, then we get space as result.
Rule 5: In Backward direction, if we specify as -1 as end index, then we get space as
result.
2. Bytes Data Type:
bytes is one of the pre-defined classes and treated as sequence data type.
The purpose of bytes data type is to implement End-To-End-Encryption/ Cipher Text (Human
Unreadable Format).
To implement End-to-End Encryption, bytes data type stores the data in the range of (0,256).
It stores 0 to 255 only.
To represent the data or to store the data in the object of bytes, we don’t have any symbolic
notation but we can convert other type of values into bytes type by using bytes().
An object of bytes data type maintains the insertion order.
An object of bytes belongs to IMMUTABLE. On modifying the value, PVM creates a new
memory space. No modification is done at original address. Modified value is placed at new
address. Item assignment is also not possible. Example: int, float, bool, complex, str, bytes,
range, tuple, set, frozenset, NoneType.
A mutable object is one which allows us to modify the values at same address.
Example: list, set, dict, bytearray.
3. ByteArray Data Type:
The Functionality of bytearray is similar to bytes data type. But an object of bytearray
belongs to mutable category objects.
4. Range Data Type:
range is one of the pre-defined classes and treated as fundamental data type.
The purpose of range data type is to store sequence of numerical integer values(range) by
maintaining equal interval of value either in forward or backward direction.
Range also stores the insertion order.
Syntaxes:
a. Var=range(value) → 0 to value-1
b. Var=range(begin,end) → begin to end-1
c. Var=range(begin,end,step) → It generates values in both forward and backward
direction from begin to end-1 with interval of step value.
End-1 → positive indexing
End+1 → negative indexing
➢ List Category Data Types:
The purpose of list category data types is to store multiple values of same or different or both
types with unique or duplicate values.
1. List Data Type: Mutable
list is one of the pre-defined classes and treated as list category data type.
Its purpose is to store multiple values of same or different or both types with unique or
duplicate values.
To store the values/elements they must be enclosed within square brackets [] and values
must be separated by comma.
Syntax: var=[val1,val2,val3,…..,valn]
It maintains the insertion order.
We can apply both slicing and indexing operations.
An object of list belongs to mutable objects.
We can create two types of lists:
a. Empty List: An empty-list is one which doesn’t contain any element and whose length is
zero. We have two syntaxes in empty list.
b. Non-Empty List: A non-empty list is one that contains elements and whose length is not
zero.
Pre-Defined Functions in list: We know that on the object of list we can perform both
indexing and slicing operations. With these operations, we can get single or multiple
elements and update single (indexing based) or multiple elements (slice based).
Along with these operations, we can perform various operations by using pre-defined
functions present in list object and they are given below.
1) append() → Adding an element at the end of existing list.
2) insert() → Inserting a value at the specified index in list. Index can be positive or
negative.
3) remove() → To remove a certain value based on value. Removes the first present
value in list.
4) pop(index) → Removes the value based on the indexing.
5) pop() → Removes the last element from the list. -1 index.
6) clear() → All the elements would be removed.
del operator → To remove multiple elements.
Del operator can only remove elements based on slicing and indexing on Mutable
Objects only and not on Immutable objects.
7) copy() →
In python, we have 2 types of copy techniques. They are -
a. Shallow Copy: The properties of shallow copy are:
1. Initial content of both the objects are same.
2. The memory addresses of the objects are different.
3. The modifications on both the objects are independent. Changes made on
one object will not affect the other object.
To implement shallow copy, we use copy()
b. Deep Copy: The properties of deep copy are same like shallow copy, but changes
made on one object will be reflected on another object as well & the memory
addresses will be same for both objects.
To achieve deep copy, we use ASSIGNMENT operator.
When slicing is applied at end, it becomes shallow copy or slice-based copy.
8) count() → To count the elements in a list.
9) index() → Gives the index of first occurrence of the specified element in a list.
enumerate function can be applied on any object having more than one value. This
function is used for obtaining index and element value from any
It helps us store the index value and elements value both.
Objects having single value only are called non-iterable objects. Ex- int, float, bool,
complex.
Iterable objects: str, byte, bytearray, list.
10) reverse() → reverse the insertion order of the elements in the list.
Reverse only operates on the object it is used on.
11) sort() → To sort the data, it should be homogeneous. The sorted elements are
placed in the object itself. We can easily reverse the order too.
12) extend() → To append the elements of a table to other table at the end of the
table. It only takes one argument at a time. It can’t take two tables at a time. Use +
operator to do so.
Inner or Nested List: The process of defining one list inside of another list is called
Inner or Nested List.
S.No Name Theory Practical
Physics Chemistry Maths Physics Chemistry
1 Satish 79 80 100 20 20
10 Satish 79 80 100 20 20
0 1 2 0 1
0 1 2 3
2. Tuple: Immutable
A tuple represents a sequence of any objects separated by commas and enclosed in
parentheses. A tuple is an immutable object, which means it cannot be changed, and we use
it to represent fixed collections of items.
Tuple is always used for maintaining constant values.
Tuple also maintains insertion order.
Object of tuple is always immutable.
We can apply both indexing and slicing operations on tuple.
There are two types of tuples that we can create.
1. Empty Tuple: An empty tuple doesn’t contain any element and its length is zero.
Syntax: t1=()
t2=tuple()
2. Non-Empty Tuple: A non-empty tuple contains some elements and its length is greater
than zero.
Pre-defined Function in tuple:
1. index()
2. count()
To sort tuple elements, we can first convert it to a list and then sort the elements.
sorted function doesn’t change the data inside the object like sort. It just takes the
data as input. We can also store the data in another object too. sorted makes the
data in list only.
With del operator we can only delete the entire tuple object only.
We can apply normal list operation inside a tuple.
➢ Set Category Data Type:
The purpose of set category data types is to store multiple values either of same type or
different type or both the types in single object with unique value, no duplicates are allowed.
1. Set: Mutable and Immutable
Set is one of the predefined data types and its purpose is to store multiple values either of
same type or different type or both the types in single object with unique value, no
duplicates are allowed.
Elements must be stored in curly braces.
An object of set category never maintains insertion order, because PVM displays the
elements in any possibility.
Indexing and Slicing can’t be done on set since it doesn’t maintain insertion order.
An object of set belongs to both mutable and immutable objects. Set doesn’t support item
assignment, but adding, deleting and modifying of elements are allowed.
Empty set:
Non-Empty Set:
Pre-defined function in set:
On the object of set, we can operate various operations by using pre-defined function. They
are –
1) clear() → To remove all the elements from a set object.
2) add() → To add element to a set object.
Append is not there because indexing is not possible in set.
3) remove() → To remove an element from set object.
4) discard() → discard function is like remove only. Discard just doesn’t give any key
error if key not present in set object.
5) pop() → it will remove any one arbitrary element of the set object.
Given order of display removes the first element only.
6) copy() → Implements shallow copy.
7) isdisjoint() → if a set A has no common elements compared to set B, then A is called
disjoint set of B.
8) issuperset() →
9) issubset() →
10) union() →
11) intersection() →
12) difference() →
13) symmetric_difference() → difference of A union B and A intersection B.
14) symmetric_difference_update() →
15) update() →
Bitwise Operators:
a. | → Bitwise OR Operatort → Union of sets
b. & → Bitwise AND Operator → Intersection
c. - → Bitwise Subtract Operator → difference of sets
d. ^ → Bitwise XOR → symmetric difference
Inner Sets:
a. Set inside set is not qpossible. Unhashable means indexing and modifying of data not
possible. In the case, because of indexing not possible.
b. List inside set is also not possible.
c. Tuple inside set is possible. Because tuple is also immutable.
d. Set inside list is possible.
e. Set inside tuple is possible.
f. List inside list is possible.
g. List inside list is possible.
h. Tuple inside tuple in possible.
i. Tuple inside list is possible.
2. Frozenset: Immutable
Frozenset is one of the pre-defined classes and treated as set data type.
The purpose of it is to store multiple values either similar type or different type or both tht
types in single object with unique values.
The element of frozenset must be obtained from objects like set, tuple and list.
Syntax: fs_obj=frozenset(set/list/tuple)
An object of frozenset never maintains insertion order because PVM can display any one of
the possibilities of frozenset object.
On object of frozenset we can-not perform indexing and slicing operations.
An object of frozenset belongs to immutable because frozenset object doesn’t support item
assignment and not modification/change/add.
There are two types of frozenset objects. They are-
a. Empty Frozenset:
b. Non-empty Frozenset:
Pre-defined Functions in frozenset:
a. copy()
Deep Copy
In general, immutable object content is not possible to copy. Where as in frozenset,
we are able to copy its content to another frozenset object. Here both original and
copied object contains same memory address and not at all possible to modify or
change their content.
b. isdisjoint()
c. issubset()
d. issuperset()
e. union()
f. intersection()
g. difference()
h. symmetric_difference()
➢ Dict Category Data Type:
Dict is one of the pre-defined classes and treated as dict data type:
The purpose of dict category data type is to store the data in the form of (Key, value).
The value of key is always unique and value may be unique or not.
Dict object doesn’t contain index and insertion order.
Syntax: dict_obj={key1:val1,key2,val2,…,keyn,valn}
There are two types of dict –
a. Empty Dict
b. Non-Empty Dict
Dict_object[value_of_key]
An object of dict is mutable, we can’t change the value of keys.
We can easily update the values of value that are stored with key.
Key-immutable
Value-mutable
Adding Data to Dict type object:
Pre-defined Functions in dict:
a. clear()
b. pop() → pop(Key)
c. popitem() → Removes one entry from the object.
d. copy() → Shallow Copy.
e. get() → To get the value of value w.r.t. a value present in a dict object.
f. keys() → To get all the names of keys in dict object.
g. values() → To get all the values from a dict object. List in tuplr.
h. items() → To get all the elements inside a dict object. All the elements are tuple kept in list.
i. update() → To update a dict object in another dict object. → Insertion + Modification
Combination of dict with dict, set, list, tuple:
a. dict in dict is possible.
b. dict inside set is not possible because inside set we can’t modify dict.
c. dict inside list is possible.
d. dict inside tuple is possible.
e. set inside dict is possible.
f. tuple inside dict is possible.
g. list inside dict is possible.
➢ NoneType Data Type:
NoneType is one of the predefined classes.
None is the keyword and treated as value of NoneType data type.
None is not False, Space and 0. None is nothing.
We can’t create an object of NoneType because it contains single value.
➢ Type Casting Technique in Python:
The process of converting one type of value into another possible type of value is called Type
Casting.
In python, we have 5 fundamental type casting techniques. They are
1. int() → convert into int type → var=int(float/bool/complex/str)
Error: Type Error (conversion of complex to int)
When we type “12.16” → in double quotes the dot is considered as special symbol and its
conversion into int gives us Value Error.
True is different from “True”.
2. float() → convert into float type → float(int/bool/complex/str)
3. bool() → convert into bool type → bool(int/float/complex/str)
ALL NON-ZERO VALUES ARE CONSIDERED AS TRUE.
ALL ZERO VALUES ARE CONSIDERED ARE FALSE.
4. complex() → convert into complex type → complex(int/float/bool/str)
5. str() → convert into str type → str(int/float/bool/complex)