0% found this document useful (0 votes)
0 views95 pages

Python Notes Software2026

The document outlines a Python programming course over several days, covering topics such as the introduction to Python, its real-time applications, features, and programming concepts. It highlights Python's advantages like simplicity, open-source nature, and platform independence, along with its dynamic typing and interpreted nature. Additionally, it discusses various applications developed using Python, including web, game, and scientific applications, while providing examples and explanations of Python's syntax and data representation.

Uploaded by

Tushar Chandel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views95 pages

Python Notes Software2026

The document outlines a Python programming course over several days, covering topics such as the introduction to Python, its real-time applications, features, and programming concepts. It highlights Python's advantages like simplicity, open-source nature, and platform independence, along with its dynamic typing and interpreted nature. Additionally, it discusses various applications developed using Python, including web, game, and scientific applications, while providing examples and explanations of Python's syntax and data representation.

Uploaded by

Tushar Chandel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 95

Day – 1

Python programming

INTRODUCTION
..............................,

Tiobe index – check which programming language trending

python trending no -1

---------------------------.

=> core Python


=> Advanced Python
=> Data science related moduled – Numpy ,pandas ,matplotlib,scipy,Scikit,seaborn,NLP...etc
----------------------------.
Pre – Requists for learning python
– no need to know about any languages
----------------------------.

What is required to become a software engineer


– excellent Coding Standards
– Coding – Hacker Ranking Examples

Day – 2

Real Time Applications devloped by using PYTHON Programming

-------------------------.

=> By using Python Programming , top world class Software develops the following
Applications/Products.

1. Web Applications
a) JAVA Lang(SUN Ms --oracle) -----> Servelts ,JSP,Spring<Hibernate ,....etc
b) c#.net Language (MS) ------> asp.net
c) PYTHON Language

requirement
---------------.

Calendar ----develop – by using java lang – 25 lines code write


Calendar same --- C#

...........................'

Python only 2 lines code write – calendar App


Less coading and More meaningful – Libraries(Modules)
Ex-

>>> import calendar


>>> print(calendar.calendar(2024))
2024

January February March


Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7 1 2 3 4 1 2 3
8 9 10 11 12 13 14 5 6 7 8 9 10 11 4 5 6 7 8 9 10
15 16 17 18 19 20 21 12 13 14 15 16 17 18 11 12 13 14 15 16 17
22 23 24 25 26 27 28 19 20 21 22 23 24 25 18 19 20 21 22 23 24
29 30 31 26 27 28 29 25 26 27 28 29 30 31

April May June


Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7 1 2 3 4 5 1 2
8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9
15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16
22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23
29 30 27 28 29 30 31 24 25 26 27 28 29 30

July August September


Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7 1 2 3 4 1
8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8
15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15
22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22
29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29
30

October November December


Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 1 2 3 1
7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8
14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15
21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
30 31

--------------------------------------------------------------------------------------------.

otp programing Python programming


ex-----.
>>> import random
>>> print(random.randint(1000,35555))
5895

------------------------------------------------.
2. Game applications
3. Arrtifical intelligence applivations (ML,DL)
4. Desktop Applications ( GUI Applications)
5. Image Processing Applications
6. Text Processing application
7. Business applications
8. Audio and video applications
9. Web Scrapping / Harvesting Applications
10. Data visulization
11. Scientific applications ex nasa
12. software devlopment
13. operating system installers ...etc

Day -3

Getting Started with Python Programming


----------------------------------------------------------.

Index
-------.
– History of Python
1. 1980 concived
2. implementation 1989
3. 1991 officially released
4. Guido van Rossum devloped
5. CWI institue in nether land by devloped
6. managed by -non comerical orginization “Python software foundation”
7. website – www.python.org
---------------------------------------------------------------------------------------------------.

versions

1. python – 1.x --- outdated


2. python 2.x---- outdated-- not support backword compatability
3. pytnon 3.x ------ new

examples\

>> print("hello world")


hello world
>>> import calendar
>>> print(calendar.month\(2023,4))
April 2023
Mo Tu We Th Fr Sa Su
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

>>> import math


>>> print(math.pow(2,3))
8.0
>>> print(math.sin(90))
0.8939966636005579
>>>

Day – 4

Feature of Python
----------------------,

python programing provide 11 feature


1. simple
2. Freeware and open source
3. platform independent language
4. Dynamically typed programming language
5. Interpreted programming language
6. High level Programming Language
7. Robust (Strong)
8. Both Functional (procedure) and object Oriented Programming Lang(OOps)
9. Extensible
10. Embedded
11. Supports Third APIs such as numpy,pandas ,matploatlib,..etc

SIMPLE

----------------;

– Python is one of the simple programming language bcoz of 3 important technical factors.
They are

Factor -1
----------. provide rich set of modules (libraries ) . so that python programmers are re-using the
predefined code wothout writing our own code.

Definition module
------------------------.
Amodule ia collection functions , Attributes and class Names .

Examples : calender , math,qr code , random, os module ,multithreading etc.

Factor – 2
------------.
day – 5

------------------------------------------------------------------------------------------------------------------------
---------------
Factor-2
------------------------------------------------------------------------------------------------------------------------
---------------
=>Python Programming Provides In-built Garbage Collection Facility by executing Garbage
Collector Program. So That Garbage Collector collects un-used memory space and improves the
performance of Python Based Applications.
----------------------------------------
Def. of Garbage Collector:
----------------------------------------
=>Garbage Collector is one of the In-Built Python Program in Python Software and It is running
Behind of Regular Python Program and whose Role is Collects Un-Used Memory space and
Improves the
Performance of Python Based Applications.
=>Hence Garbage Collector takes take about Automatic Memory Management.
------------------------------------------------------------------------------------------------------------------------
---------------
Factor-3
------------------------------------------------------------------------------------------------------------------------
---------------
=>Python Programming Lang Provides User-Friendly Syntaxes and Makes the programmer to
develop Error-Free Programs within Limited Span of Time.
=====================================X================================

>>> pi=22/7
>>> print(pi)
3.142857142857143
>>> =3.4
File "<python-input-4>", line 1
=3.4
^
SyntaxError: invalid syntax
>>> a=3.4
>>> print("%0.25f" %a)
3.3999999999999999111821580
>>> print("%0.75f" %a)
3.399999999999999911182158029987476766109466552734375000000000000000000000000
>>>

============.
Simple

– python programming is eady and hence python is simple .

2. Free ware and open source


Freeware
----------;
i any software download freely

example – python,java-----

Open Source:
---------------.
– the standard name of python – cpython
– many software compney came forwaord and customized CPYTHON and developed their
own inhouse tools.
– CPYTHON – python distributions

some of thepython distributions


1. jpython or jython--- javabased applications running
2. Iron Python OR Ipython – used C# applications
3. ruby python- ruby applications
4. Micro python – used to run / develop micro controller applications
5. Anaconda python – used to run Big Data/ Hadoop Based Applications
6. stackless python – used to concurrency applications ..etc

Day – 6

Platform Independent Language

=>A Platform is nothing but Type of OS being Used to run Application / Program.
=>In this context, we have two types of Programming languages. They are

1. Platform Dependent Lang


2. Platform Independent Lang
--------------------------------------------------------------------------
1. Platform Dependent Lang
--------------------------------------------------------------------------
=>In Platform Dependent Lang, Data Types differes from One OS to Another OS.
Example: C,C++....etc

--------------------------------------------------------------------------
2. Platform Independent Lang
--------------------------------------------------------------------------
=>In Platform Independent Lang, Data Types memory remains Same on All Types OSes.
=>In Effective Platform Independent Lang, all types of Values will store in the form of OBJECTs
and they can store Un-Limited amount of data
=>Hence java Object contains Size Restricted where Python Objects contains Un-limited Size and
unlimited values can store.

NOTE: IN PYTHON ALL VALUES ARE STOREd IN THE OF OBJECTS.


Examples: Java, Python.

Day – 7
==============================================
4. Dynamically Typed
==============================================
=>In IT, we have Two Types of Programming languages. They are

1. Static Typed Programming Languages


2. Dynamically Typed Programming Languages
-----------------------------------------------------------------------------------------------------------------------
1. Static Typed Programming Languages
-----------------------------------------------------------------------------------------------------------------------
=>In Static Typed Programming Languages, It is mandatory to Specify Variable Declaration for
storing
Inputs in main memory of Computer.

Examples Statements:
---------------------------------
int x,y,z; // Variable Declaration--mandatory
x=10
y=30
z=x+y

Examples Lang: C, C++, Java, C#.net....etc


-----------------------------------------------------------------------------------------------------------------------
2. Dynamically Typed Programming Languages
-----------------------------------------------------------------------------------------------------------------------
=>In Dynamically Typed Programming Languages, depends on type of value we are assiging,
whose data type automatoically / Implicitly assigned by Python Execution Environment
=> There is No Need to write Variable declaration in Dynamically Typed Programming Languages

Example Stmts:
---------------------
>>> a=100
>>> b=200
>>> c=a+b
>>> print(a,type(a))-----------100 <class 'int'>
>>> print(b,type(b))----------200 <class 'int'>
>>> print(c,type(c))----------300 <class 'int'>
Examples: Python
===============================================
5. Interpreted Programming
===============================================
=>When we develop any python program, we must give some file name with an extension .py (File
Name.py).
=>When we execute python program, two process taken place internally
a) Compilation Process
b) Execution Process.
=>In COMPILATION PROCESS, The python Source Code submitted to Python Compiler and It
reads the source Code, Check for errors by verifying syntaxes and if no errors found then Python
Compiler Converts into Intermediate Code called BYTE CODE with an extension .pyc
(FileName.pyc). If erros found in source code then we get error displyed on the console.
=>In EXECUTION PROCESS, The PVM reads the Python Intermediate Code(Byte Code) and
Line by Line and Converted into Machine Understable Code (Executable or binary Code) and It is
read by OS and Processer and finally Gives Result.
=>Hence In Python Program execution, Compilation Process and Execution Process is taking place
Line by Line conversion and It is one of the Interpretation Based Programming Language.
--------------------------------------------------------------------
Definition of PVM ( Python Virtual Machine )
--------------------------------------------------------------------

=>PVM is one program in Python Software and whose role is to read LINE by LINE of Byte Code
and Converted into Machine Understable Code (Executable or binary Code)

DAY – 8

High level

– 1. low level programming language


– 2. High level programming language
=======================================
– 6. High Level Programming
– =======================================
– =>In this context, we have two types of languages. They are

– 1. Low Level Programming Languages
– 2. High Level Programming Languages
– -----------------------------------------------------------------
– 1. Low Level Programming Languages:
– -----------------------------------------------------------------
– =>In Low Programming Languages, data is always stored in the form of low level values
such as Binary data, Octal Data and Hexa Decimal data. These Number System are not
directly understandable end-users

– Example : a=0b1010101010
– b=0xBEE
– c=0o23
– -----------------------------------------------------------------
– 2. High Level Programming Languages
– -----------------------------------------------------------------
– =>In these languages, Internally, Even the programmer specifies the data in the form of Low
Level Format such Binary data, Octal Data and Hexa Decimal data, automatically Python
Programming Language Execution Environment Converts into High Level data, which is
understandable by end-users . Hence Python is one of the High Level Programming
Languages.

– Examples:
– ----------------
– >>> a=0b101010111110000
– >>> b=0b10101111000
– >>> print(a)-----------------------22000
– >>> print(b)----------------------1400
– >>> a=0xBEE
– >>> print(a)-----------------------3054
– >>> bin(22000)-----------------'0b101010111110000'
– >>> hex(3054)----------------'0xbee'
– ======================================x===========================
=====

Day -9
– Data Repersentation in python

========================================
What is Literal--Types of Literals
========================================
=>Literals are nothing but input values passing as Input to the Program.
=>In otherwords, The values passing to the program as an input are called Literals.
=>In Python Programming, Primaraly, we have 5 types of Literals. They are
1. Integer Literals / Values
2. Floating point Literals
3. String Literals
4. Boolean Literals
5. Collection Literals
6.

=====================================================================
Importance of Identifiers OR Variables

=====================================================================
=>We know that All types Literals are stored in main memory by having memory space.
=>To Process values which are present in memory space , Programmers must give distinct names to
cerated memory spaces. These distict names makes us to identify the values present in memory
space and hence they are called IDENTIFIERS.
=>The IDENTIFIER Values are Changing/ Varying during Program Execution and hence
IDENTIFIERS are also called VARIABLES.
=>Hence All types of LITERALS are stored in the form of VARIABLES and all Variables are
called OBJECTS.
------------------------------
Definition of Variable:
-------------------------------
=>A Variable is an Identifier whose values are Changing During Program Execution.
=======================================================================
=======
Rules for using Variables / Identifiers in Python Programming
=======================================================================
=======
=>To use Variables in Python Programming, Python Programmer must use the following

RULE-1: The Variable Name is a combination of Alphabets, Digits and Special Symbol Under
score ( _ )
----------- only

RULE-2: The First Letter of Variable Must starts Either with Alphabet or Under Score ( _ )
------------
Examples:
---------------
sal=34----valid
123sal=56--Invalid
$sal=45---invalid
sal1=34----valid
_sal_=46--valid
__a=56--valid
__=56--valid
-------------
RULE-3: Within the Variable Name, Special Symbols are not allowed except Under score( _ )
------------
Examples:
---------------
emp sal=56---invalid
emp$sal=56--Invalid
emp-sal=45--invalid
emp_sal=56--valid
emp_sal$ibm=67--invalid
emp_sal_ibm=67--valid
---------------
RULE-4: We should not Keywords as Variables Names bcoz Keywords are reserved words and
they
---------------Contains Some Special meaning to the Lang Compilers.

Examples:
---------------
if=56--Invalid
else=67--Invalid
for=56--Invalid
if1=56---valid
_else=56--valid
_for=67--valid
------------
RULE-5 : All the Variable Names are Case Sensitive
------------
Examples:
-----------------
AGE=45
age=99
Age=97
aGe=96
print(AGE,age,Age,aGe)-----------------45 99 97 96

Day – 10

=================================================
Data Types in Python
=================================================
=>The purpose of DataTypes in Python is that " To allocate Sufficient Amount of Memory Space in
main
memory of computer and Inputs can stored".
=>Python Programming Provides 14 data types and Classified into 6 Categories. They are

I. Fundamental Cattegory Data Types.


1. int (immutable)
2. float (immutable)
3. bool (immutable)
4. complex (immutable)
II. Sequence Category Data Types
1. str (immutable)
2. bytes (immutable)
3. bytearray(mutable)
4. range (immutable)
III. List Category Data Types (Collection or Data Structures)
1. list (mutable)
2. tuple (immutable)
IV. Set Category Data Types (Collection or Data Structures)
1. set (mutable and immutable)
2. frozenset (immutable)
V. Dict Category Data Types (Collection or Data Structures)
1. dict (mutable)
VI. NoneType Category Data Type
1. NoneType

----------------------------------------------------------------------------.

====================================================
I. Fundamental Category Data Types.
====================================================
=>The purpose of Fundamental Category Data Types is that " To Store Single Value".
=>In Python Programming, we have 4 data types in Fundamental Category. They are
1. int
2. float
3. bool
4. complex
----------------------------------.

===========================================
1. int
===========================================
Properties:
---------------------
=>'int' is one of the pre-defined class name and treated as Fundamental data Type.
=>The purpose of int data type is that " To store Integer data OR Whole Numbers OR Integral data
(Numbers without Decimal places)".
----------------
Examples:
------------------------------- -------------
Python Instructions Output
-------------------------------- -------------
>>> a=123
>>> print(a)----------------------------------123
>>> type(a)----------------------------------<class 'int'>
>>> id(a)-------------------------------------140716113134184
---------------------------------------
>>> sno=4567
>>> print(sno,type(sno))----------------4567 <class 'int'>
>>> print(id(sno))-------------------------1785231794992
-------------------------------------------------------------------------------
>>> print(sno,type(sno),id(sno))----4567 <class 'int'> 1785231794992
NOTE: One Can Use Class Names as Variable Names
Examples:
-----------------
>>> int=34 # here int is an object / variables
>>> print(int,type(int))---------------------34 <class 'int'>
------------------------------------------------------------------------------------------------------------------------
=>With int data type, In Python Programming, along with Integer data, we can also store Different
Number System Values. In Any Programming Lang, we have 4 Types of Number Systems. They
are

1. Decimal Number System


2. Binary Number System
3. Octal Number System
4. Hexa Decimal Number System
------------------------------------------------------------------------------------------------------------------------
-
1. Decimal Number System
------------------------------------------------------------------------------------------------------------------------
-
=>Decimal Number System is one the Default Number System in Programming lang
=>This Number System Contains
Digits: 0 1 2 3 4 5 6 7 8 9 ---Total digits=10
base: 10
=>base 10 Literals are callled Decimal Number System Values
------------------------------------------------------------------------------------------------------------------------
-
2. Binary Number System
------------------------------------------------------------------------------------------------------------------------
-
=>Binary Number System is Understandable by OS and Processor.
=>This Number System Contains
Digits: 0 1 ---Total digits=2
base: 2
=>base 2 Literals are callled Binary Number System Values
=>In python programming, To Store Binary Data, Binary data must be preceded by letter either 0b
OR 0B.
=>Syntax: varname=0b Binary data
(OR)
varname=0B Binary data
=>Even we store Binary data in Python Programming, Python Programming Execution
environment automatically / Implcitly Converted into Decimal Number System Types.
-----------------
Examples:
-----------------
>>> a=0b1101
>>> print(a,type(a))-------------------------13 <class 'int'>
-------------------------------
>>> a=0B1111
>>> print(a,type(a))-------------------------15 <class 'int'>
---------------------------------
>>> a=0B101110
>>> print(a,type(a))-------------------------46 <class 'int'>
--------------------------------
>>> bin(13)------------------------------------'0b1101'
>>> bin(15)------------------------------------'0b1111'
>>> bin(46)------------------------------------'0b101110'
NOTE: bin() is used converting any number system data into Binary Number System Type.
------------------------------------------------------------------------------------------------------------------------
3. Octal Number System
------------------------------------------------------------------------------------------------------------------------
-
=>Octal Number System is Understandable by Micro processor Kits --8086
=>This Number System Contains
Digits: 0 1 2 3 4 5 6 7 -----Total digits=8
base:8
=>base 8 Literals are callled Octal Number System Values
=>In python programming, To Store Octal Data, Octal data must be preceded by letter either 0o OR
0O.
=>Syntax: varname=0o Octal data
(OR)
varname=0O Octal data

=>Even we store Octal data in Python Programming, Python Programming Execution environment
automatically / Implcitly Converted into Decimal Number System Types.
Examples:
-------------------
>>> a=0o33
>>> print(a,type(a))----------------------27 <class 'int'>
>>> a=0O123
>>> print(a,type(a))---------------------83 <class 'int'>
>>> a=0o128--------------------------------SyntaxError: invalid digit '8' in octal literal
NOTE:
---------------
NOTE: oct() is used converting any number system data into Octal Number System Type.
Examples:
-------------------
>>> oct(27)-----------------'0o33'
>>> oct(83)----------------'0o123'

Day -11
4. Hexa Decimal Number System
------------------------------------------------------------------------------------------------------------------------
-
=>Hexa Decimal Number System used in development OSes
=>This Number System Contains
Digits: 0 1 2 3 4 5 6 7 8 9
A(10) B(11) C(12) D(13) E(14) F(15)-----Total ---16

=>Base 16 Literals are callled Hexa Decimal Number System Values


=>In python programming, To Store Hexa Decimal Data, Hexa Decimal data must be preceded by
letter either 0x OR 0X.
=>Syntax: varname=0x Hexa Decimal Data
(OR)
varname=0X Hexa Decimal data

=>Even we store Hexa Decimal data in Python Programming, Python Programming Execution
environment automatically / Implcitly Converted into Decimal Number System Types.
----------------------------------
Examples:
----------------------------------
>>> a=0xAC
>>> print(a,type(a))-------------------------------172 <class 'int'>
>>> a=0xBEE
>>> print(a,type(a))-------------------------------3054 <class 'int'>
>>> a=0XFaCe
>>> print(a,type(a))-------------------------------64206 <class 'int'>
>>> a=0xACCER-----------------------SyntaxError: invalid hexadecimal literal
>>> a=0xBEEK---------SyntaxError: invalid hexadecimal literal
NOTE: hex() is used converting any number system data into Hexa Decimal Number System
Type.
>>> hex(172)----------------------------------------'0xac'
>>> hex(3054)--------------------------------------'0xbee'
>>> hex(64206)------------------------------------'0xface'
------------------------------------------------------------------------------------------------------------------------
-
Special Points:
--------------------------------
>>> a=0b1010
>>> b=oct(a)
>>> print(b,type(b))------------0o12 <class 'str'>
-------------------------
>>> a=0xF
>>> c=oct(a)
>>> print(c,type(c))--------------0o17 <class 'str'>
-----------------------------------------
>>> a=23
>>> d=oct(a)
>>> print(d,type(d))------------0o27 <class 'str'>
=================================================
>>> a=0o12
>>> b=bin(a)
>>> print(b)------------------0b1010
--------------------
>>> a=0xE
>>> b=bin(a)
>>> print(b)--------------------0b1110
------------------
>>> a=7
>>> b=bin(a)
>>> print(b)-------------------0b111
====================================================
>>> a=0b1111
>>> b=hex(a)
>>> print(b)--------------------0xf
---------------------
>>> a=0o17
>>> b=hex(a)
>>> print(b)------------------0xf
-------------------------------------------------------------------------
>>> a=14
>>> b=hex(a)
>>> print(b)------------------0xe
========================================================
Q) What are the Various Base Conversion Functions in Python?
ANS: the Various Base Conversion Functions in Python are

1) bin()
2) oct()

3) hex()
==========================================================
2. float
==========================================================
Properties
--------------------------
=>'float' is one of the pre-defined class name and treated as Fundamental data Type.
=>The purpose of float data type is that "To store Real Constant values OR Float OR Double
Pointing
(Number with Decimal Places)".
=>float data type never allows us to represent / Store Binary,Octal and Hexa Decimal Values
=>float data type allows us to store Scientific Notation data. The Advantage of Scientific is that To
take Less Memory space for bigger floating point Values.
--------------------
Examples:
--------------------
>>> a=12.34
>>> print(a,type(a))-----------------------------------12.34 <class 'float'>
>>> b=0.9
>>> print(b,type(b))----------------------------------0.9 <class 'float'>
------------------------------
>>> a=10
>>> b=1.2
>>> c=a+b
>>> print(a,type(a))---------------------------------10 <class 'int'>
>>> print(b,type(b))--------------------------------1.2 <class 'float'>
>>> print(c,type(c))--------------------------------11.2 <class 'float'>
--------------------------------------------------------------------------------------------------------
>>> a=0b1010.0b1111------------SyntaxError: invalid decimal literal
>>> a=0o13.0o23----------------SyntaxError: invalid decimal literal
>>> a=0xAC.0XBEE------------SyntaxError: invalid decimal literal
>>> a=0b1010.0xAC------------SyntaxError: invalid decimal literal
>>> a=0o12.0b1010------------SyntaxError: invalid decimal literal
--------------------------------------------------------------------------------------------------------
>>> a=3e2
>>> print(a,type(a))--------------------300.0 <class 'float'>
----------------------------------
>>> a=4e-2

>>> print(a,type(a))---------------0.04 <class 'float'>


-----------------------------------------------------------
>>> a=0.00000000000000000000000000000000000000000000006
>>> print(a,type(a))---------6e-47 <class 'float'>

=======================================
3. bool
========================================
=>'bool' is one of the pre-defined class name and treated as Fundamental data Type.
=>The purpose of bool data type is that "To Store True False Values".
=>In Python Programming True, False are Called Keywords and It is treated as values of bool data
type.
=>In Python Programming, Internally, The value of True is treated as 1 and False is treated as 0.

Examples:
---------------------------------------
>>> a=True
>>> print(a,type(a))--------------------------------True <class 'bool'>
>>> b=False
>>> print(b,type(b))------------------------------False <class 'bool'>
------------------------------
>>> a=true--------------NameError: name 'true' is not defined
>>> a=false----------------------NameError: name 'false' is not defined
----------------------------------------------------------------------------------------------------------
>>> a=True
>>> b=False
>>> print(a+b)------------------------1
>>> print(a-b)------------------------1
>>> print(2*True+True+False)------------3
>>> print(2+True*3+False)-------------5
>>> print(0b1010-True+2*True)----------11
>>> print(True/True)----------------------1.0
>>> print(True//True)------------------------1
>>> print(False//True)----------------------0
#Most Imp
>>> print(True//False)---------------------------ZeroDivisionError: integer division or modulo by zero
======================================x================================
=========

Day – 12

$. Complex

================================================
4. complex
================================================
Properties
-----------------
=>'complex' is one of the pre-defined class and treated as Fundamental data type.
=>The purpose of complex data type is that "To store Complex Values / Imaginary values".
=>The Gegeral Notation of compelx data type is given bellow
x+yj or x-yj
Here 'x' is called Real Part
Here 'y' is caqlled Imaginary part
and j Represents sqrt(-1) or sqr(j)=-1
=>Internally, Real and Imgainary parts of Complex Object are treated as float data type
=>To Extract the real and Imginary parts of Complex object, we have 2 pre-defined attributes. They
are
1) real
2) imag

Syntax: complexobj.real------>Gives Real Part of Complex object


complexobj.imag----->Gives Imaginary Part of Complex Object
=>On the object of complex data type, we can perform various Arithmetic Operation such as
Addition, Substraction, Multiplication..etc
-------------------
Examples:
-------------------
>>> a=2+3j
>>> print(a,type(a))----------------------------------(2+3j) <class 'complex'>
>>> b=-2-4j
>>> print(b,type(b))--------------------------------(-2-4j) <class 'complex'>
>>> a=1.2+3.4j
>>> print(a,type(a))--------------------------------(1.2+3.4j) <class 'complex'>
>>> b=-2.3-4.5j
>>> print(b,type(b))-------------------------------(-2.3-4.5j) <class 'complex'>
>>> a=12+4.5j
>>> print(a,type(a))-------------------------------(12+4.5j) <class 'complex'>
>>> b=-12.5-4j
>>> print(b,type(b))------------------------------(-12.5-4j) <class 'complex'>
---------------------------------------------
>>> a=2j
>>> print(a,type(a))------------------2j <class 'complex'>
>>> b=-5j
>>> print(b,type(b))-----------------(-0-5j) <class 'complex'>
>>> a=2.3j
>>> print(a,type(a))-----------------2.3j <class 'complex'>
>>> b=-2.6j
>>> print(b,type(b))------------- (-0-2.6j) <class 'complex'>
----------------------------------------------------------------------------------------
>>> a=10+3j
>>> print(a,type(a))------------------(10+3j) <class 'complex'>
>>> print(a.real)---------------------- 10.0
>>> print(a.imag)-------------------- 3.0
>>> b=2.5+4.6j
>>> print(b,type(b))--------------- (2.5+4.6j) <class 'complex'>
>>> print(b.real)------------------- 2.5
>>> print(b.imag)------------------ 4.6
----------------------------------------------------------------------------------------
>>> a=-3.5j
>>> print(a,type(a))------------------- (-0-3.5j) <class 'complex'>
>>> print(a.real)----------------------- -0.0
>>> a=2.5j
>>> print(a,type(a))------------------- 2.5j <class 'complex'>
>>> print(a.real)------------------------ 0.0
>>> print(a.imag)---------------------- 2.5
>>> a=-1+4.5j
>>> print(a,type(a))----------------- (-1+4.5j) <class 'complex'>
>>> print(a.real)--------------------- -1.0
>>> print(a.imag)--------------------- 4.5
---------------------------------------------------------------------------------------------------------
>>> a=2+3j
>>> b=3+8j
>>> c=a+b
>>> print(c,type(c))-----------------(5+11j) <class 'complex'>
----------------------
>>> d=a-b
>>> print(d,type(d))------------(-1-5j) <class 'complex'>
-----------------
>>> e=a*b
>>> print(e,type(e))-----------(-18+25j) <class 'complex'>
==================================x====================================
===

==================================================
II. Sequence Category Data Types
==================================================
=>The purpose of Sequence Category Data Types is that "To store Sequence of values".
=>In Python programming, we have 4 data types in Sequence Category . They are

1. str
2. bytes
3. bytearray
4. range
=======================================================================
=
=================================================
1. str ( Part-1 )
=================================================
iNDEX
-----------
=>Purpose of str
=>Definition of str
=>Types of strs
=>Notation used for storing str data
=>Memory Management of str data
=>Operations on str Data
a) Indexing
b) Slicing
=>Programmin Examples
------------------------------------------------------------------------------------------------------------------------
----------------
Properties
----------------------------
=>'str' is one of the pre-defined class and treated as Sequence Data Type.
=>The purpose of str data type is that "To store String data or text data or Alphanumeric data or
numeric data or special symbols within double Quotes or single quotes or tripple double quotes and
tripple single quotes. "
------------------------
=>Def. of str:
-----------------------
=>str is a collection of Characters or Alphanumeric data or numeric data or any type of data
enclosed within double Quotes or single quotes or tripple double quotes and tripple single quotes. "
----------------------------
Types of Str data
-----------------------------
=>In Python Programming, we have two types of Str Data. They are
1. Single Line String Data
2. Multi Line String Data
-----------------------------------------
1. Single Line String Data:
-----------------------------------------
=>Syntax1:- varname=" Single Line String Data "
(OR)
=>Syntax2:- varname=' Single Line String Data '
=>With the help double Quotes (" ") and single Quotes (' ') we can store single line str data only but
not possible to store multi line string data.
---------------------------------------------------------------------------------------------------------------------
2. Multi Line String Data:
-----------------------------------------
=>Syntax1:- varname=" " " String Data1
String Data2
------------------
String data-n " " "

(OR)

=>Syntax2:- varname=' ' ' String Data1


String Data2
------------------
String data-n ' ' '

=>With the help OF tripple double Quotes (" " " " " ") and Tripple single Quotes (' ' ' ' ' ') we
can store single line str data and multi line string data.
------------------------------------------------------------------------------------------------------------------------
------------------
Examples:
------------------------------------------------------------------------------------------------------------------------
--------------
>>> s1="Python"
>>> print(s1,type(s1))--------------Python <class 'str'>
>>> s2='Python'
>>> print(s2,type(s2))-------------Python <class 'str'>
>>> s3='A'
>>> print(s3,type(s3))-----------A <class 'str'>
>>> s4="A"
>>> print(s4,type(s4))--------------A <class 'str'>
------------------------------
>>> s5="Python3.10"
>>> print(s5,type(s5))--------------Python3.10 <class 'str'>
>>> s6="123456"
>>> print(s6,type(s6))----------123456 <class 'str'>
>>> s7="Python Programming 1234$Rossum_Guido"
>>> print(s7,type(s7))----------Python Programming 1234$Rossum_Guido <class 'str'>
---------------------------
>>> addr1= "Guido van Rossum
------------------------------
SyntaxError: unterminated string literal (detected at line 1)
>>> addr1= ' Guido van Rossum
-----------------------------
SyntaxError: unterminated string literal (detected at line 1)
-------------------------------------
>>> addr1=" " "Guido van Rossum
... HNO:3-4,Hill Side
... Python Software Foundation
... Nether Lands-56"""
>>> print(addr1,type(addr1))
Guido van Rossum
HNO:3-4,Hill Side
Python Software Foundation
Nether Lands-56 <class 'str'>
-------------------
>>> addr2=' ' 'Travis Oliphant
... HNO:23-45, Sea Side
... Numpy Organization
... nethr lands-67 '''
>>> print(addr2,type(addr2))
Travis Oliphant
HNO:23-45, Sea Side
Numpy Organization
nethr lands-67 <class 'str'>
------------------------------------------
>>> s7=" " " Python " " "
>>> print(s7,type(s7))--------------Python <class 'str'>
>>> s8=' ' ' Python ' ' '
>>> print(s8,type(s8))-----------------Python <class 'str'>
>>> s9=" " " Z " " "
>>> print(s9,type(s9))-------------Z <class 'str'>
>>> s10=' ' ' K ' ' '
>>> print(s10,type(s10))------------K <class 'str'>
------------------------
>>> s1="Python Programmin"
>>> print(s1,type(s1))--------------------Python Programmin <class 'str'>
>>> s1--------------------------------------- ' Python Programmin '
>>> s7=" " " Python " " "
>>> print(s7,type(s7))------------------Python <class 'str'>
>>> s7-------------------------------------- ' Python '
-------------------------------
>>> s1=" " "Python is an oop lang
... python is also fun Prog lang
... Python is also Modular Prog lang " " "
>>> print(s1,type(s1))
Python is an oop lang
python is also fun Prog lang
Python is also Modular Prog lang <class 'str'>
>>> s1
' Python is an oop lang \n python is also fun Prog lang \n Python is also Modular
Prog lang '
=================================x=====================================
=
day – 13

==============================================
Operations on str Data
==============================================
=>On str data, we can perform Two Types of Operations. They are
1. Indexing
2. Slicing
------------------------------------------------------------------------------------------------------------------------
----------------
1. Indexing
------------------------------------------------------------------------------------------------------------------------
----------------
=>The Process of Obtaining Single Value from given Main Str object is called Indexing
=>Syntax: strobj[Index]
=>here strobj is an object of <class,'str'>
=>index represents Either +Ve Index or -Ve Index
=>If we enter Valid Index value then we get Corresponding Inxdexed Value.
=>If we enter InValid Index value then we get IndexError.
---------------------------
Examples
---------------------------
>>> s="PYTHON"
>>> print(s,type(s))-------------------PYTHON <class 'str'>
>>> print(s[0])----------------------P
>>> print(s[-6])---------------------P
>>> print(s[-1])--------------------N
>>> print(s[5])---------------------N
>>> print(s[3])--------------------H
>>> print(s[-3])-------------------H
>>> print(s[-2])-------------------O
>>> print(s[-4])-------------------T
>>> print(s[-5])------------------Y
>>> print(s[2])-------------------T
>>> s[2]----------------------------'T'
>>> s[-2]--------------------------'O'
>>> print(s[8])-------------------IndexError: string index out of range
>>> print(s[-12])----------------IndexError: string index out of range
---------------------
>>> s="123453456"
>>> print(s,type(s))---------------123453456 <class 'str'>
>>> s[2]----------------------'3'
>>> s[-1]-------------------'6'
>>> s[0]--------------------'1'
>>> s[len(s)-1]-------------'6'
>>> s[-len(s)]---------------'1'
--------------------------------------------
>>> s="JAVA"
>>> print(s,type(s))-------------JAVA <class 'str'>
>>> len(s)-------------------------4
>>> s[len(s)-1]-----------------'A'
>>> s[-len(s)]------------------'J'
>>> s[len(s)-len(s)]-------------'J'
>>> s[-2]---------------------------'V'
>>> s[2]----------------------------'V'
>>> s[len(s)]---------------------------------IndexError: string index out of range
---------------------------------------------------
>>> s="MISSISSIPPI"
>>> s[len(s)-1]----------------'I'
>>> s[-len(s)]-----------------'M'
>>> s[len(s)]-----------------------IndexError: string index out of range
------------------------------------------------------------------------------------------------------------------------
----------------
2.Slicing
------------------------------------------------------------------------------------------------------------------------
----------------
=>The Process obtaining Range of Values OR Sub String from Given main Str Object is called
Slicing.
=>To Perform Slicing Operations, we have 5 Syntaxes. They are
------------------------------------------------------------------------------------------------------------------------
----------------
Syntax1: strobj[BEGIN:END]
------------------------------------------------------------------------------------------------------------------------
---------------
=>This Syntax generates Range of Values OR Sub String from BEGIN Index to END-1 Index
provided
BEGIN<END Otherwise we never get any result OR Space OR ' ' as a Result
Examples:
-----------------------------
>>> s="PYTHON"
>>> print(s,type(s))-------------------PYTHON <class 'str'>
>>> s[0:3]--------------------------------'PYT'
>>> s[2:6]--------------------------------'THON'
>>> s[1:6]---------------------------------'YTHON'
>>> s[2:1]---------------------------------' '
>>> s[0:6]----------------------------------'PYTHON'
----------------------------
>>> s="PYTHON"
>>> print(s,type(s))-----------------PYTHON <class 'str'>
>>> s[-6:-2]---------------------------'PYTH'
>>> s[-3:-1]---------------------------'HO'
>>> s[-6:-3]---------------------------'PYT'
>>> s[-3:-6]---------------------------' '
>>> s[-6:-1]---------------------------'PYTHO'
--------------------------------------------------------------------------------------------------
Sub Rule: strobj[BEGINPOSINDEX:ENDNEGATIVEINDEX]
--------------------------------------------------------------------------------------------------
=>This Syntax Gives Range of Characters from BEGINPOSINDEX to ENDNEGATIVEINDEX-1
provided
BEGINPOSINDEX > ENDNEGATIVEINDEX. Otherwise we get Space or NO Result OR ' ' as
a result.
-----------------
Examples
-----------------
>>> s="PYTHON"
>>> print(s,type(s))----------PYTHON <class 'str'>
>>> s[1:-2]-------------'YTH'
>>> s[2:-1]--------------'THO'
>>> s[-3:1]--------------' '
------------------------------------------------------------------------------------------------------------------------
----------------
Syntax:2 : strobj[BEGIN : ]
------------------------------------------------------------------------------------------------------------------------
----------------
=>In This Syntax, we are Specifying BEGIN Index and we did't Specify END Index.
=>If we don't specify END Index then PVM Takes END Index as len(strobj)
(OR)
=>If we don't specify END Index then PVM Takes BEGIN INDEX Character to Last Character.
----------------
Examples:
----------------
>>> s="PYTHON"
>>> print(s,type(s))--------------PYTHON <class 'str'>
>>> s[2:]----------------------------'THON'
>>> s[0:]----------------------------'PYTHON'
>>> s[3:]----------------------------'HON'
>>> s[4:]----------------------------'ON'
>>> s[1:]---------------------------'YTHON'
-------------------------------
>>> s="PYTHON"
>>> print(s,type(s))----------------PYTHON <class 'str'>
>>> s[-3:]-----------------------------'HON'
>>> s[-2:]-----------------------------'ON'
>>> s[-6:]-----------------------------'PYTHON'
>>> s[-5:]----------------------------'YTHON'
>>> s[-4:]----------------------------'THON'
>>> s[-1:]----------------------------'N'
-----------------------------------------------------
Special Points
-----------------------------------------------------
>>> s="PYTHON"
>>> print(s,type(s))-----------------------PYTHON <class 'str'>
>>> s[-12:]-----------------------------------'PYTHON'
>>> s[-23:]----------------------------------'PYTHON'
>>> s[23:]----------------------------------' '
>>> s[2:4]---------------------------------- 'TH'
>>> s[12:44]------------------------------- ' '
>>> s[-66:-1]------------------------------ 'PYTHO'
>>> s[2:122]------------------------------ 'THON'
>>> s[2:-122]-------------------------------' '
>>> s[2:-1]----------------------------------'THO'
>>> s[2:-22]--------------------------------' '
------------------------------------------------------------------------------------------------------------------------
-----------------
Syntax3: strobj[ : End]
------------------------------------------------------------------------------------------------------------------------
-----------------
=>In This Syntax, we are Specifying END Index and we did't Specify BEGIN Index.
=>If we don't specify BEGIN Index then PVM Takes BEGIN Index as 0 OR -len(strobj)
(OR)
=>If we don't specify BEGIN Index then PVM Takes First Character to END-1 Index.
--------------------------------
Examples:
--------------------------------
>>> s="PYTHON"
>>> print(s,type(s))--------------PYTHON <class 'str'>
>>> s[:3]----------------------------'PYT'
>>> s[:6]----------------------------'PYTHON'
>>> s[:5]---------------------------'PYTHO'
>>> s[:4]---------------------------'PYTH'
------------------------------
>>> s="PYTHON"
>>> print(s,type(s))-------------PYTHON <class 'str'>
>>> s[:-3]---------------------------'PYT'
>>> s[:-2]--------------------------'PYTH'
>>> s[:-1]--------------------------'PYTHO'
>>> s[:-4]--------------------------'PY'
>>> s[:-5]---------------------------'P'
------------------------------------------------------------------------------------------------------------------------
-----------------
Syntax4: strobj[ : ]
------------------------------------------------------------------------------------------------------------------------
-----------------
=>In This Syntax, we are not Specifying BEGIN Index and END Index
=>If we don't specify BEGIN Index and END Index then PVM Takes BEGIN Index as 0 OR -
len(strobj) and
END Index as len(strobj) or -1
(OR)
=>If we don't specify BEGIN Index and END Index then PVM Takes from First Character(0th
Index or
-len(strobj) index ) to last Character ( len(strobj) or -1).
=>Hence This Syntax always gives Total String Data.
---------------------------------------------
Examples
---------------------------------------------
>>> s="PYTHON"
>>> print(s,type(s))-------------------PYTHON <class 'str'>
>>> s[:]-----------------------------------'PYTHON'
>>> s="JAVA PROG"
>>> print(s,type(s))-------------------JAVA PROG <class 'str'>
>>> s[:]----------------------------------'JAVA PROG'
>>> s[0:]--------------------------------'JAVA PROG'
>>> s[:len(s)]--------------------------'JAVA PROG'
>>> s[-len(s):]-------------------------'JAVA PROG'
NOTE: All the above Syntaxes are Extracting the data from strobj in Forward Direction with
Default
Step value 1.
------------------------------------------------------------------------------------------------------------------------
-------------------
Syntax 5: strobj[BEGIN: END : STEP]
------------------------------------------------------------------------------------------------------------------------
-------
RULE-1: Here BEGIN, END and STEP Values can be either +VE or -VE
-------------

RULE-2: If STEP Value is +VE then PVM Takes the Range of Characters from BEGIN Index to
END-1
------------- Index in FORWARD Direction With Step Value provided BEGIN INDEX < END
INDEX Otherwise
we get Space or ' ' as a result
-------------
RULE-3: If STEP Value is -VE then PVM Takes the Range of Characters from BEGIN Index to
END+1
------------- Index in BACKWARD Direction With Step Value provided BEGIN INDEX > END
INDEX Otherwise we get Space or ' ' as a result
-------------
RULE-4 : In FORWARD Direction, If END Value is 0 Then we get Space or ' ' as a result
-------------

-------------
RULE-5: In BACKWARD Direction, If END Value is -1 Then we get Space or ' ' as a result
-------------
------------------------------------------------------------------------------------------------------------------------
-----
Examples: RULE-2
------------------------------------------------------------------------------------------------------------------------
---
>>> s="PYTHON"
>>> print(s)-------------------------------PYTHON
>>> s[0:4]---------------------------------'PYTH'
>>> s[0:4:1]------------------------------'PYTH'
>>> s[2:6:1]------------------------------'THON'
>>> s[2:6:2]------------------------------'TO'
>>> s[0:6:2]-----------------------------'PTO'
>>> s[0:6:3]-----------------------------'PH'
>>> s[ : : ]--------------------------------'PYTHON'
>>> s[ : :2]--------------------------------'PTO'
>>> s[ : :3]--------------------------------'PH'
>>> s[-6:-1:2]----------------------------'PTO'
>>> s[-6: :]-------------------------------'PYTHON'
>>> s[:6:]---------------------------------'PYTHON'
>>> s[0:6:]-------------------------------'PYTHON'
>>> s[:-1:]-------------------------------'PYTHO'
----------------------------------------------------------------------------------------------------------
Examples: RULE-3
---------------------------------------------------------------------------------------------------------
>>> s="PYTHON"
>>> print(s)-----------------------------PYTHON
>>> s[::]---------------------------------'PYTHON'
>>> s[::1]-------------------------------'PYTHON'
>>> s[::-1]-------------------------------'NOHTYP'
>>> s[::-2]--------------------------------'NHY'
>>> s[0:6:-2]-----------------------------''
>>> s[5:0:-1]----------------------------'NOHTY'
>>> s[::-3]-------------------------------'NT'
>>> s[4: :-2]----------------------------'OTP'
>>> s[: :2]------------------------------'PTO'
>>> s[: :2][::-1]------------------------'OTP'
>>> s[-1:-7:-1]-------------------------'NOHTYP'
>>> s[-1::-1]---------------------------'NOHTYP'
>>> s[-1::-2]---------------------------'NHY'
>>> s[-2::-2]---------------------------'OTP'
>>> s[2:6:][::-1]----------------------'NOHT'
>>> s[2:6:]----------------------------'THON'
-------------------------------------------------------------------------------------------------------
Examples-------------RULE-4
-------------------------------------------------------------------------------------------------------
>>> s="PYTHON"
>>> print(s)-----------------------------PYTHON
>>> s[2:0:1]-----------------------------' '
>>> s[:0:1]------------------------------' '
>>> s="JAVA PROG"
>>> print(s)----------------------------JAVA PROG
>>> s[:0:1]-----------------------------''
>>> s[:0]------------------------------' '
>>> s[:0:3]--------------------------' '
-------------------------------------------------------------------------------------------------------
Examples-------------RULE-5
-------------------------------------------------------------------------------------------------------
>>> s="PYTHON"
>>> print(s)--------------------PYTHON
>>> s[::-1]---------------------'NOHTYP'
>>> s[ :-1:-1]------------------' '
>>> s[ :-1:-3]-----------------' '
>>> s[ :-1:-4]------------------' '
-------------------------------------------------------------------------------------------------------
Special Points
------------------------------------------------------------------------------------------------------
>>> "PYTHON"[::-1]----------------------'NOHTYP'
>>> "PYTHON"[::-1]=="PYTHON"-------------False
>>> "PYTHON"[::2]=="PYTHON"[::-1][::2]--------False
>>> "MOM"[::-1]=="MOM"----------------------True
>>> "MOM"[::-1]=="MOM"[::]-----------------True
>>> "LIRIL"[::-1]=="LIRIl"[::-1]--------------False
------------------------------------------------------------------------------------------------------

day – 14
====================================================
Mutability and Immutability objects
====================================================
--------------------------------
Mutable Object
--------------------------------
=>A Mutbale object is one, Which allows us to Perform the Changes / Modify / Update the values
at
Same Memory Address
-----------------
Examples:
-----------------
=>bytearray,list,set,dict
--------------------------------
Immutable Object
--------------------------------
=>An Immutbale object is one, which will satisfy the following properties.
a) The value of Immutable object never allows us to Modify at same address
( OR Value of Immutable object can be modified and Modified value can be
placed at New Memory Address)
b) Immutable objects does not support Item Assigment

Examples: int, float, complex, bool, str, bytes, range,tuple,set,frozenset


Day -15

Type casting Techniques in python programming

----------------;

The process of converting One Possible Type of Value into Another Possible Type is called type
casting .

– In python Programming , we have 5 fundamental Type casting Technoques . They are

1. int()
2. float()
3. bool()
4. complex()
5. str()

int ()

– int() is used for converting One possible Type of value into int type value.
Sytax: varname = int(float/bool/complex/str)

Example-1: float type value to int type--->


>>> a= 12.34
>>> print(a,type(a))
12.34 <class 'float'>
>>> b=int(a)
>>> print(b,type(b))
12 <class 'int'>
>>>
>>> a=0.5
>>> print(a,type(a))
0.5 <class 'float'>
>>> b=int(a)
>>> print(b,type(a))
0 <class 'float'>
>>>

Example-2: bool type value to int type --->

>>> a=True
>>> print(a,type(a))
True <class 'bool'>
>>> b=int(a)
>>> print(b,type(a))
1 <class 'bool'>
>>>

Example -3 : complex type value to int type ---->


>>> a=2+3j
>>> print(a,type(a))
(2+3j) <class 'complex'>
>>> b=int(a)
Traceback (most recent call last):
File "<python-input-18>", line 1, in <module>
b=int(a)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex'
>>>

Example-4 : str type value to int value

>>> a="tushar"
>>> print(a,type(a))
tushar <class 'str'>
>>> b=int(a)
Traceback (most recent call last):
File "<python-input-21>", line 1, in <module>
b=int(a)
ValueError: invalid literal for int() with base 10: 'tushar'
>>>

Case – 1

str int --- int possible


>>> a="12"
>>> b=int(a)
>>> print(b,type(b))
12 <class 'int'>
>>>

Case -2 str float --- int not possiable

>>> a="12.34"
>>> print(a,type(a))
12.34 <class 'str'>
>>> b=int(a)
Traceback (most recent call last):
File "<python-input-27>", line 1, in <module>
b=int(a)
ValueError: invalid literal for int() with base 10: '12.34'
>>>

case-3 str bool -- int --- not possiable

>>> a="True"
>>> print(a,type(a))
True <class 'str'>
>>> b=int(a)
Traceback (most recent call last):
File "<python-input-30>", line 1, in <module>
b=int(a)
ValueError: invalid literal for int() with base 10: 'True'
>>>

case-4 pue str – int not possible

>>> a="Pyrhon"
>>> print(a,type(a))
Pyrhon <class 'str'>
>>> b=int(a)
Traceback (most recent call last):
File "<python-input-33>", line 1, in <module>
b=int(a)
ValueError: invalid literal for int() with base 10: 'Pyrhon'
>>>

Type casting

Float()

float() is to process of converting One possiable type value another into float type value .

Syntax: varname=float(int/bool/complex/str)
............................................................................,

Example -1 : int type ---> float type possible

>>> a=100
>>> print(a,type(a))
100 <class 'int'>
>>> b=float(a)
>>> print(b,type(b))
100.0 <class 'float'>
>>>

Example -2 : bool type --- float type possible

>>> a=True
>>> print(a,type(a))
True <class 'bool'>
>>> b=float(a)
>>> print(b,type(b))
1.0 <class 'float'>
>>>

Eample -3 : complex type --- float type not possiable

>>> a=2+3j
>>> print(a,type(a))
(2+3j) <class 'complex'>
>>> b=float(a)
Traceback (most recent call last):
File "<python-input-47>", line 1, in <module>
b=float(a)
TypeError: float() argument must be a string or a real number, not 'complex'
>>>

example -4 : str type --> float type

case1 str int---> float --> possiable


>>> a="12"
>>> print(a,type(a))
12 <class 'str'>
>>> b=float(a)
>>> print(b,type(b))
12.0 <class 'float'>
>>>

case – 2

str float --- float possiable

>>> a=12.34
>>> print(a,type(a))
12.34 <class 'float'>
>>> b=float(a)
>>> print(b,type(b))
12.34 <class 'float'>
>>>

case – 3

str bool ---> float --> not possable

>> a="Ture"
>>> print(a,type(a))
Ture <class 'str'>
>>> b=float(a)
Traceback (most recent call last):
File "<python-input-58>", line 1, in <module>
b=float(a)
ValueError: could not convert string to float: 'Ture'
>>>

case -4

str complex – float ---. not possiable


> a="2+3j"
>>> print(a,type(a))
2+3j <class 'str'>
>>> b=float(a)
Traceback (most recent call last):
File "<python-input-61>", line 1, in <module>
b=float(a)
ValueError: could not convert string to float: '2+3j'
>>>

case -5

Pure str --> float not possiable

> a="python3.11"
>>> print(a,type(a))
python3.11 <class 'str'>
>>> b=float(a)
Traceback (most recent call last):
File "<python-input-66>", line 1, in <module>
b=float(a)
ValueError: could not convert string to float: 'python3.11'
>>>

Bool
– All non zero value _ True
– all zero value - False

syntax: varname =bool(int/float/complex/str)

Example -1 : int type ---bool type – possable

>>> a=123
>>> print(a,type(a))
123 <class 'int'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'>
>>>

Example -2 : float type --- bool type

>>> a=12.34
>>> print(a,type(a))
12.34 <class 'float'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'>
>>>
>>> a=0.000000000000000000000000000000000000000000000000000\1
>>> print(a,type(a))
1e-52 <class 'float'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'>
>>>

example -3 : complex type --- bool type -- possable

>> a=2+3j
>>> print(a,type(a))
(2+3j) <class 'complex'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'>
>>>

example – 4 : str type----bool type

case -1

str int -bool -- possiable

a="123"
>>> print(a,type(a))
123 <class 'str'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'>

case -2

str float --- bool --- possiable

>>> a="12.34"
>>> print(a,type(a))
12.34 <class 'str'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'>
>>>

case -3

str bool --- bool – possiable


>>> a="True"
>>> print(a,type(a))
True <class 'str'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'boo
case -4

---str complex to bool


>> a=4+5.6j
>>> print(a,type(a))
(4+5.6j) <class 'complex'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'>
>>>

case – 5

pure str --- bool – possiable

> a="python"
>>> print(a,type(a))
python <class 'str'>
>>> b=bool(b)
>>> print(b,type(b))
True <class 'bool'

4. Complex

Syntax: varname = comlex(int/float/bool/str)

Example -1 : int type ---> complex type ---> possiable

>>> a=123
>>> print(a,type(a))
123 <class 'int'>
>>> b=complex(a)
>>> print(b,type(b))
(123+0j) <class 'complex'>
>>>

Example -2
: float type to complex ----possiable

a=True
>>> print(a,type(a))
True <class 'bool'>
>>> b=complex(b)
>>> print(b,type(b))
(123+0j) <class 'complex'>

example – 3 bool – possiable

example – 4 str type --- complex type


case -1

str int --- complex – possible

case -2

str float – complex-- possiable

case – 3

str float --- complex --- not possiable

>> a="True"
>>> print(a,type(a))
True <class 'str'>
>>> b=comlex(b)
Traceback (most recent call last):
File "<python-input-119>", line 1, in <module>
b=comlex(b)
^^^^^^
NameError: name 'comlex' is not defined. Did you mean: 'complex'?
>>>

case -4

str complex ---- complex ----- possiable

case -5 pure str complex --- not possiable

> a="python+3j"
>>> print(a,type(a))
python+3j <class 'str'>
>>> b=Complex(a)
Traceback (most recent call last):
File "<python-input-126>", line 1, in <module>
b=Complex(a)
^^^^^^^
NameError: name 'Complex' is not defined. Did you mean: 'complex'?
>>>

5. Str ()

Syntax: varname str(int,float,bool,complex)

-----------------------------------------------------------.
Examples :
>>> a=123
>>> print(a,type(a))
123 <class 'int'>
>>> b=str(a)
>>> print(b,type(b))
123 <class 'str'>
>>>

> a=23.455
>>> print(a,type(a))
23.455 <class 'float'>
>>> b=str(a)
>>> print(b,type(b))
23.455 <class 'str'>

a=True
>>> print(a,type(a))
True <class 'bool'>
>>> b=str(a)
>>> print(b,type(b))
True <class 'str'>
>>>

a=23+4j
>>> print(a,type(a))
(23+4j) <class 'complex'>
>>> b=str(a)
>>> print(b,type(b))
(23+4j) <class 'str'>
>>>

all possiable
DAY – 16

Bytes

---------,

===================================================
2. bytes
====================================================
Properties
------------------
=>'bytes' is one of the pre-defined class name and treated as Sequence Data Type.
=>The purpose of bytes data type is that "To organize the Numerical Integer values ranges from
(0,256) for the implementation of End-to-End Encryption".
=>bytes data type does not contains any symbolic notations for oraganizing (0,256) data. But we
can convert any type of Value(s) into bytes type by using bytes()
=>Syntax: varname=bytes(object)
=>An object of bytes belongs to immutable bcoz bytes object does not support Item Assigment.
=>On the object of bytes, we can perform both Indexing and Slicing Operations.
=>An object of bytes maintains Insertion Order (Which is nothing but, whatever the order we insert
the data, In the same order data will be displayed).
------------------------------------------------------------------------------------------------------------------------
-------------------
Examples
------------------------------------------------------------------------------------------------------------------------
-------------------
>>> lst=[10,34,56,100,256,0,102]
>>> print(lst,type(lst))----------------------[10, 34, 56, 100, 256, 0, 102] <class 'list'>
>>> b=bytes(lst)----------------------------ValueError: bytes must be in range(0, 256)
>>> lst=[10,-34,56,100,255,0,102]
>>> print(lst,type(lst))-------------------[10, -34, 56, 100, 255, 0, 102] <class 'list'>
>>> b=bytes(lst)--------------------------ValueError: bytes must be in range(0, 256)
>>> lst=[10,34,56,100,255,0,102]
>>> print(lst,type(lst))-------------------[10, 34, 56, 100, 255, 0, 102] <class 'list'>
>>> b=bytes(lst)
>>> print(b,type(b))---------------------b'\n"8d\xff\x00f' <class 'bytes'>
>>> for val in b:
... print(val)
...
10
34
56
100
255
0
102

>>> print(b,type(b))----------------b'\n"8d\xff\x00f' <class 'bytes'>


>>> print(b[0])--------------------10
>>> print(b[-1])-------------------102
>>> print(b[0:4])--------------- b'\n"8d'
>>> for val in b[0:4]:
... print(val)
...
10
34
56
100
>>> b[0]----------------------------10
>>> b[0]=123---------------TypeError: 'bytes' object does not support item assignment
==============================x========================================
=======

===============================================
3. bytearray
====================================================
Properties
------------------
=>'bytearray' is one of the pre-defined class name and treated as Sequence Data Type.
=>The purpose of bytearray data type is that "To organize the Numerical Integer values ranges from
(0,256) for the implementation of End-to-End Encryption".
=>bytearray data type does not contains any symbolic notations for oraganizing (0,256) data. But
we can convert any type of Value(s) into bytearray type by using bytearray()
=>Syntax: varname=bytearray(object)
=>An object of bytearray belongs to mutable bcoz bytearray object supports Item Assigment.
=>On the object of bytearray, we can perform both Indexing and Slicing Operations.
=>An object of bytearray maintains Insertion Order (Which is nothing but, whatever the order we
insert the data, In the same order data will be displayed).
------------------------------------------------------------------------------------------------------------------------
--------------------
NOTE: The Functionality of bytes and bytearray are exactly same but bytes object belongs to
Immutable bcoz bytes object does not support Item assigment where bytearray object blongs to
Mutable bcoz bytearray object supports Item Assigment.
------------------------------------------------------------------------------------------------------------------------
--------------------
Examples:
------------------------------------------------------------------------------------------------------------------------
--------------------
>>> tpl=(10,34,56,100,256,0,102)
>>> print(tpl,type(tpl))-----------------(10, 34, 56, 100, 256, 0, 102) <class 'tuple'>
>>> ba=bytearray(tpl)--------------------ValueError: byte must be in range(0, 256)
>>> tpl=(-10,34,56,100,255,0,102)
>>> print(tpl,type(tpl))-------(-10, 34, 56, 100, 255, 0, 102) <class 'tuple'>
>>> ba=bytearray(tpl)-------------ValueError: byte must be in range(0, 256)
-------------------------
>>> tpl=(10,34,56,100,255,0,102)
>>> print(tpl,type(tpl))------------(10, 34, 56, 100, 255, 0, 102) <class 'tuple'>
>>> ba=bytearray(tpl)
>>> print(ba,type(ba))------------bytearray(b'\n"8d\xff\x00f') <class 'bytearray'>
-------------------------------
>>> tpl=(10,34,56,100,255,0,102)
>>> print(tpl,type(tpl))-----------------(10, 34, 56, 100, 255, 0, 102) <class 'tuple'>
>>> ba=bytearray(tpl)
>>> print(ba,type(ba))---------------------bytearray(b'\n"8d\xff\x00f') <class 'bytearray'>
>>> for val in ba:
... print(val)
...
10
34
56
100
255
0
102
>>> for val in ba[::-1]:
... print(val)
...
102
0
255
100
56
34
10
>>> for val in ba:
... print(val)
...
10
34
56
100
255
0
102
>>> print(ba,type(ba),id(ba))---------bytearray(b'\n"8d\xff\x00f') <class 'bytearray'> 2149788291504
>>> ba[0]--------------10
>>> ba[-1]------------102
>>> ba[0]=123 # Updating / item assoigment on bytearray object--allowed
>>> for val in ba:
... print(val)
...
123
34
56
100
255
0
102
>>> print(ba,type(ba),id(ba))-----bytearray(b'{"8d\xff\x00f') <class 'bytearray'> 2149788291504
------------------------------------------
>>> b=bytes(ba) # Converting bytearray into bytes
>>> print(b,type(b))---------------b'{"8d\xff\x00f' <class 'bytes'>
>>> for val in b:
... print(val)
...
123
34
56
100
255
0
102
>>> b[0]---------------------123
>>> b[0]=12------TypeError: 'bytes' object does not support item assignment
>>> x=bytearray(b) # Converting bytes into bytearray
>>> print(x,type(x),id(x))----bytearray(b'{"8d\xff\x00f') <class 'bytearray'> 2149788291888
>>> for v in x:
... print(v)
...
123
34
56
100
255
0
102
>>> x[1]----------------------34
>>> x[1]=234
>>> for v in x:
... print(v)
...
123
234
56
100
255
0
102
>>> print(x,type(x),id(x))-----bytearray(b'{\xea8d\xff\x00f') <class 'bytearray'> 2149788291888
------------------------------------------------------------------------------------------------------------------------
--------------------

Day – 17

==============================================
4. range
==============================================
Properties
-------------------
=>'range' is one of the pre-defined class and treated as Sequence data type
=>The purpose of range data type is that "To Store Sequence of Numerical Integer Values with
Equal
Interval of Value."
=>An object of range belongs to Immutable bcoz range object does not support Item Assignment.
=>On the object of range, we can perform Both Indexing Slicing Operations
=>The range of Values can be stored either in forward or Backward Directions.
=>range data type contains 3 syntaxes. They are
------------------------------------------------------------------------------------------------------------------------
--------------------
Syntax-1: varname=range(Value)
------------------------------------------------------------------------------------------------------------------------
--------------------
=>This Syntax generates range of values from 0 to Value-1
Examples:
-----------------
>>> r=range(6)
>>> print(r,type(r))
range(0, 6) <class 'range'>
>>> for v in r:
... print(v)
...
0
1
2
3
4
5
>>> for val in range(6):
... print(val)
...
0
1
2
3
4
5
>>> for val in range(10):
... print(val)
...
0
1
2
3
4
5
6
7
8
9
------------------------------------------------------------------------------------------------------------------------
--------------------
Syntax-2 : varname=range(Begin,End)
------------------------------------------------------------------------------------------------------------------------
--------------------
=>This Syntax generates range of values from Begin to End-1
Examples:
------------------
>>> r=range(10,16)
>>> print(r,type(r))
range(10, 16) <class 'range'>
>>> for val in r:
... print(val)
...
10
11
12
13
14
15
>>> for val in range(10,16):
... print(val)
...
10
11
12
13
14
15
>>> for val in range(10,16):
... print(val,end=" ") # 10 11 12 13 14 15

NOTE: The Syntax-1 and Syntax-2 generates range of values in FORWARD DIRECTION with
Default
Interval 1.
------------------------------------------------------------------------------------------------------------------------
--------------------
Syntax-3: varname=range(Begin,End,Step)
------------------------------------------------------------------------------------------------------------------------
--------------------
=>This Syntax generates range of values from Begin to End-1 by maintaining Equal Interval value
in the form Step either in Forward Direction or Backdirection.
-----------------------------------
Examples:
------------------------------------
>>> r=range(10,21,2)
>>> for val in r:
... print(val)
...
10
12
14
16
18
20
>>> for val in range(10,21,2):
... print(val)
...
10
12
14
16
18
20
------------------------------------------------------------------------------------------------------------------------
------------
Implementation of range data type
------------------------------------------------------------------------------------------------------------------------
------------
Q1) 0 1 2 3 4 5 6 7 8 9 10--------range(11)
>>> for val in range(11):
... print(val)
...
0
1
2
3
4
5
6
7
8
9
10
------------------------------------------------------------------------------------------------------------------------
------------
Q2) 10 11 12 13 14 15 16 17 18 19 20--range(10,21)
>>> for val in range(10,21):
... print(val)
...
10
11
12
13
14
15
16
17
18
19
20
------------------------------------------------------------------------------------------------------------------------
------------
Q3) 1000 1001 1002 1003 1004 1005----range(1000,1006)
>>> for val in range(1000,1006):
... print(val)
...
1000
1001
1002
1003
1004
1005
------------------------------------------------------------------------------------------------------------------------
------------
Q4) 10 12 14 16 18 20-------range(10,21,2)
>>> for val in range(10,21,2):
... print(val)
...
10
12
14
16
18
20
------------------------------------------------------------------------------------------------------------------------
------------
Q5) 100 110 120 130 140 150 160 170 180 190 200----range(100,201,10)
>>> for v in range(100,201,10):
... print(v)
...
100
110
120
130
140
150
160
170
180
190
200
------------------------------------------------------------------------------------------------------------------------
------------
Q6) 10 9 8 7 6 5 4 3 2 1-----range(10,0,-1)
>>> for v in range(10,0,-1):
... print(v)
...
10
9
8
7
6
5
4
3
2
1

------------------------------------------------------------------------------------------------------------------------
------------
Q7) 100 90 80 70 60 50 40 30 20 10 0------range(100,-1,-10)
>>> for hyd in range(100,-1,-10):
... print(hyd)
...
100
90
80
70
60
50
40
30
20
10
0
------------------------------------------------------------------------------------------------------------------------
------------
Q8) -10 -11 -12 -13 -14 -15-------- range(-10,-16,-1)
>>> for val in range(-10,-16,-1):
... print(val)
...
-10
-11
-12
-13
-14
-15
------------------------------------------------------------------------------------------------------------------------
------------
Q9) -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 ----range(-100,-9,10)
>>> for val in range(-100,-9,10):
... print(val)
...
-100
-90
-80
-70
-60
-50
-40
-30
-20
-10
------------------------------------------------------------------------------------------------------------------------
------------
10) -5 -4 -3 -2 -1 0 1 2 3 4 5 -----range(-5,6,1) OR range(-5,6)
>>> for val in range(-5,6,1):
... print(val)
...
-5
-4
-3
-2
-1
0
1
2
3
4
5
>>> for val in range(-5,6):
... print(val)
...
-5
-4
-3
-2
-1
0
1
2
3
4
5
------------------------------------------------------------------------------------------------------------------------
------------
>>> for val in range(-1000,-1201,-50):
... print(val)
...
-1000
-1050
-1100
-1150
-1200
>>> r=range(-1000,-1201,-50)
>>> r[0]-------------------------1000
>>> r[-1]-------------------------1200
>>> for val in r[0:2]:
... print(val)
...
-1000
-1050
>>> r[0]=2000----TypeError: 'range' object does not support item assignment
-----------------
>>> for val in range(10,21,2)[::-1]:
... print(val)
...
20
18
16
14
12
10
==============================================================
III. List Category Data Types (Collection or Data Structures)

====================================================================
III. List Category Data Types (Collection or Data Structures)

====================================================================
=>The purpose of List Category Data Types is that "To store Multiple Values either of same Type
OR Different Type OR Both the Types in Single Object with Unique and Duplicate Values".
=>In Python Programming, we have 2 data types in List Category. They are
1. list (mutable)
2. tuple (immutable)
==============================x========================================
=======

====================================================================
==============================================
1. list
==============================================
Index:
------------------------------------------------------------------------
=>Properties of list
=>Types of list
a) emty list
b) non-empty list
=>Operations on list
=>Pre-defined functions in list
=>Nested List / Inner List
=>Programming Examples

DAY = 18 ***

Properties of list
------------------------------------------------------------------------------------------------------------------------
-------------------
=>'list' is one of the pre-defined class and treated as list data type
=>The purpose of list data type is that " To store Multiple Values either of same Type OR Different
Type
OR Both the Types in Single Object with Unique and Duplicate Values".
=>The Values / Elements of list must be stored / Organized with Square Brackets [ ] and Values
must be
separted by comma.
=>An object of list maintains Insertion order.
=>On object of list, we can perform Both Indexing and Slicing Operations.
=>An object of list belongs to Mutable
=>W.r.t list class, we can create 2 types of list objects. They are
a) Empty List
b) Non-Empty List
--------------------------
a) Empty List:
--------------------------
=>An empty list is one, which does not contain any Elements and whose length is 0.
=>Syntax: varname=[]
(OR)
varname=list()
--------------------------
b) Non-Empty List:
--------------------------
=>An Non-Empty list is one, which contains Elements and whose length is >0.
=>Syntax: varname=[Val1,Val2.....Val-n]
(OR)
varname=list(object)
------------------------------------------------------------------------------------------------------------------------
----------
Examples:
------------------------------------------------------------------------------------------------------------------------
----------
>>> l1=[10,20,30,10,40,50,20,10]
>>> print(l1,type(l1))----------------[10, 20, 30, 10, 40, 50, 20, 10] <class 'list'>
>>> l2=[20,"Rossum",34.56,True,2+3j]
>>> print(l2,type(l2))---------------------[20, 'Rossum', 34.56, True, (2+3j)] <class 'list'>
>>> l2[0]----------------20
>>> l2[-1]-------------(2+3j)
>>> l2[1:4]-----------['Rossum', 34.56, True]
>>> l2[::2]--------------[20, 34.56, (2+3j)]
>>> l2[::-1]-----------[(2+3j), True, 34.56, 'Rossum', 20]
---------------------------
>>> l2=[20,"Rossum",34.56,True,2+3j]
>>> print(l2,type(l2),id(l2))--------[20, 'Rossum', 34.56, True, (2+3j)] <class 'list'> 2705927635008
>>> l2[0]=30
>>> print(l2,type(l2),id(l2))----[30, 'Rossum', 34.56, True, (2+3j)] <class 'list'> 2705927635008
>>> l2[2:4]=[44.55,False]
>>> print(l2,type(l2),id(l2))----[30, 'Rossum', 44.55, False, (2+3j)] <class 'list'> 2705927635008
---------------------------------------
>>> l1=[10,"Rossum",34.56]
>>> print(l1,type(l1),len(l1))----------------[10, 'Rossum', 34.56] <class 'list'> 3
>>> l2=[]
>>> print(l2,type(l2),len(l2))--------------- [] <class 'list' > 0
OR
>>> l3=list()
>>> print(l3,type(l3),len(l3))-------------- [] <class 'list'> 0
-------------------------------------
>>> l1=[10,20,30,40,50,60]
>>> print(l1,type(l1))-------------------------[10, 20, 30, 40, 50, 60] <class 'list'>
>>> b=bytes(l1)
>>> print(b,type(b))-------------------------b'\n\x14\x1e(2<' <class 'bytes'>
>>> l2=list(b)
>>> print(l2,type(l2))---------------------[10, 20, 30, 40, 50, 60] <class 'list'>
>>> s="MISSISSIPPI"
>>> l3=list(s)
>>> print(l3,type(l3))-----['M', 'I', 'S', 'S', 'I', 'S', 'S', 'I', 'P', 'P', 'I'] <class 'list'>
------------------------
>>> a=[10]
>>> print(a,type(a))------------------[10] <class 'list'>
>>> x=100
>>> b=list(x)------------------TypeError: 'int' object is not iterable
To solve the above Error, Use the following
>>> b=list([x])
>>> print(b,type(b))--------------------[100] <class 'list'>
>>> b=list(x,)------------TypeError: 'int' object is not iterable
--------------------------------

==================================================
Pre-defined functions in list
==================================================
=>We know that, on the object of list, we can perform Both Indexing and Slicing Operations.
=>Along with Indexing and Slicing Operations, we can Perform Various Operations by using Pre-
Defined
Functions present in list object. They are
------------------------------------------------------------------------------------------------------------------------
----------------------
1. append()
------------------------------------------------------------------------------------------------------------------------
----------------------
Syntax: listobj.append(Value)
=>This Function is used for adding the values to list object at end.
--------------------------
Example
-------------------------
>>> lst=[10,"Rossum",34.56]
>>> print(lst,id(lst))----[10, 'Rossum', 34.56] 2705927639808
>>> lst.append("PYTHON")
>>> print(lst,id(lst))----[10, 'Rossum', 34.56, 'PYTHON'] 2705927639808
>>> lst.append(True)
>>> lst.append(1+2.5j)
>>> print(lst,id(lst))----[10, 'Rossum', 34.56, 'PYTHON', True, (1+2.5j)] 2705927639808
------------------------------------------------------------------------------------------------------------------------
----------------------
2. insert()
------------------------------------------------------------------------------------------------------------------------
----------------------
Syntax: listobj.insert(Index,Value)
=>This Function is used for adding the value to list object at Specified Index
=>When we enter Invalid Possitive Index then the value inserted at Last/End of List object
=>When we enter Invalid Negative Index then the value inserted at First of List object
-------------------
Examples
-------------------
>>> lst=[10,"Rossum",34.56]
>>> print(lst,id(lst))---------[10, 'Rossum', 34.56] 2705923376704
>>> lst.insert(2,"PYTHON")
>>> print(lst,id(lst))-----------[10, 'Rossum', 'PYTHON', 34.56] 2705923376704
>>> lst[-1]=44.56
>>> print(lst,id(lst))--------[10, 'Rossum', 'PYTHON', 44.56] 2705923376704
>>> lst.insert(2,True)
>>> print(lst,id(lst))-----[10, 'Rossum', True, 'PYTHON', 44.56] 2705923376704
>>> lst.insert(-1,2+3j)
>>> print(lst,id(lst))-----[10, 'Rossum', True, 'PYTHON', (2+3j), 44.56] 2705923376704
-------------------------------------
>>> lst=[10,"Rossum",34.56]
>>> print(lst,id(lst))-----------[10, 'Rossum', 34.56] 2705927639296
>>> lst.insert(10,"PYTHON")
>>> print(lst,id(lst))-----------[10, 'Rossum', 34.56, 'PYTHON'] 2705927639296
>>> lst.insert(-10,"HYD")
>>> print(lst,id(lst))----------['HYD', 10, 'Rossum', 34.56, 'PYTHON'] 2705927639296
------------------------------------------------------------------------------------------------------------------------
----------------------
3. clear()
------------------------------------------------------------------------------------------------------------------------
----------------------
Syntax: listobj.clear()
=>This Function is used for Removing all the elements of Non-Empty List object
=>When we call clear() on empty list object then we get No Output / None
Examples:
------------------
>>> lst=[10,"Rossum",34.56]
>>> print(lst,id(lst),len(lst))---------------[10, 'Rossum', 34.56] 2705927639808 3
>>> lst.clear()
>>> print(lst,id(lst),len(lst))------------ [] 2705927639808 0
----------------------------------
>>> lst.clear() -------------- No Ouput
(OR)
>>> print(lst.clear())----------None
>>> [].clear()-------------------No Output
(OR)
>>> print([].clear())
None
>>> print(list().clear())----------None
------------------------------------------------------------------------------------------------------------------------
-
4. remove()----Based on Value
------------------------------------------------------------------------------------------------------------------------
----------------------
=>Syntax: listobj.remove(Value)
=>This Function is used for Removing the First Occurence of Specified Element of list object.
=>If the Specified Element does not exist in list object then we get ValueError.
----------------------
=>Examples:
----------------------
>>> lst=[10,"Rossum",34.56,"Python"]
>>> print(lst,len(lst))--------------------[10, 'Rossum', 34.56, 'Python'] 4
>>> lst.remove("Rossum")
>>> print(lst,len(lst))------------------[10, 34.56, 'Python'] 3
>>> lst.remove(34.56)
>>> print(lst,len(lst))--------------------[10, 'Python'] 2
>>> lst.remove("Python")
>>> print(lst,len(lst))------------------[10] 1
>>> lst.remove(10)
>>> print(lst,len(lst))------------------[] 0
>>> lst.remove("Python")--------------ValueError: list.remove(x): x not in list
>>> list().remove(100)-------------------ValueError: list.remove(x): x not in list
---------------------------------------
>>> lst1=[10,20,30,10,30,"Python",True]
>>> print(lst1,len(lst1))---------------[10, 20, 30, 10, 30, 'Python', True] 7
>>> lst1.remove(10)
>>> print(lst1,len(lst1))--------------[20, 30, 10, 30, 'Python', True] 6
>>> lst1.remove(10)
>>> print(lst1,len(lst1))--------------[20, 30, 30, 'Python', True] 5
>>> lst1.remove(30)
>>> print(lst1,len(lst1))--------------[20, 30, 'Python', True] 4
>>> lst1.remove(30)
>>> print(lst1,len(lst1))--------------[20, 'Python', True] 3
------------------------------------------------------------------------------------------------------------------------
-
5. pop(index)----Index Based
------------------------------------------------------------------------------------------------------------------------
----------------------
=>Syntax: listobj.pop(index)
=>This Function is used for Removing the Element of listobj based on Index.
=>If the Index is invalid then we get IndexError
-------------------
Examples:
-------------------
>>> lst1=[10,20,30,10,30,"Python",True]
>>> print(lst1)--------------------------[10, 20, 30, 10, 30, 'Python', True]
>>> lst1.pop(3)-------------------------10
>>> print(lst1)--------------------------[10, 20, 30, 30, 'Python', True]
>>> lst1.pop(-4)-----------------------30
>>> print(lst1)--------------------------[10, 20, 30, 'Python', True]
>>> lst1.pop(0)------------------------10
>>> print(lst1)--------------------------[20, 30, 'Python', True]
>>> lst1.pop(0)------------------------20
>>> print(lst1)------------------------[30, 'Python', True]
>>> lst1.pop(0)----------------------30
>>> print(lst1)-------------------------['Python', True]
>>> lst1.pop(0)-----------------------'Python'
>>> print(lst1)------------------------[True]
>>> lst1.pop(0)-----------------------True
>>> print(lst1)-------------------------[]
>>> lst1.pop(0)--------------------------IndexError: pop from empty list
>>> list().pop(-4)------------------------IndexError: pop from empty list
>>> list().pop(4)-------------------------IndexError: pop from empty list
------------------------------------------------------------------------------------------------------------------------
-------------------
6. pop()
------------------------------------------------------------------------------------------------------------------------
----------------------
Syntax: listobj.pop()
=>This Function is used for Removing always Last Element of Listobject.
=>If we call pop() on empty list object then we get IndexError
------------------
Examples:
------------------
>>> lst=[10,"Rossum",34.56,"Python"]
>>> print(lst)----------------------------[10, 'Rossum', 34.56, 'Python']
>>> lst.pop()--------------------------'Python'
>>> print(lst)---------------------------[10, 'Rossum', 34.56]
>>> lst.pop()-------------------------34.56
>>> print(lst)-------------------------[10, 'Rossum']
>>> lst.pop()--------------------------'Rossum'
>>> print(lst)-------------------------[10]
>>> lst.pop()--------------------------10
>>> print(lst)-------------------------[]
>>> lst.pop()--------------------------IndexError: pop from empty list
---------------------------------------------------------------------------
>>> list().pop()----------------IndexError: pop from empty list
>>> [].pop()---------------------IndexError: pop from empty list

day -19

NOTE: del operator--Most Imp


---------
Syntax1: del objname[Index]---->Removing the element based on Index
Syntax2: del objname[Begin:End:Step]--->Removing the Elements Based in Slicing Operations
Syntax3: del objname--------->Removing the entire object
------------------
Examples
------------------
>>> lst=[10,"Sagatika",66.66,"OUCET","HYD"]
>>> print(lst,type(lst),id(lst))-----------[10, 'Sagatika', 66.66, 'OUCET', 'HYD'] <class 'list'>
2302481486656
>>> del lst[-2]
>>> print(lst,type(lst),id(lst))----------[10, 'Sagatika', 66.66, 'HYD'] <class 'list'> 2302481486656
>>> del lst[0:2]
>>> print(lst,type(lst),id(lst))---------[66.66, 'HYD'] <class 'list'> 2302481486656
>>> lst=[10,"Sagatika",66.66,"OUCET","HYD"]
>>> del lst[::2]
>>> print(lst,type(lst),id(lst))--------['Sagatika', 'OUCET'] <class 'list'> 2302485776384
>>> del lst
>>> print(lst,type(lst),id(lst))-----NameError: name 'lst' is not defined.
------------------------------------------------------------------------------------------------------------------------
-------------------
7) index()
------------------------------------------------------------------------------------------------------------------------
-------------------
Syntax: listobj.index(Value)
------------
=>This Function is used for Finding Index of First Occurence of Specified Element in List object.
=>if the Specified Element not present in List object then we get ValueError.
----------------
Examples:
----------------
>>> lst=[10,20,30,40,10,60,70,10,30]
>>> print(lst)-------------[10, 20, 30, 40, 10, 60, 70, 10, 30]
>>> lst.index(10)---------0
>>> lst.index(20)---------1
>>> lst.index(30)----------2
>>> lst.index(300)----------ValueError: 300 is not in list
>>> list().index(10)---------ValueError: 10 is not in list
>>> [].index(-12)-------------ValueError: -12 is not in list
------------------------------------------------------------------------------------------------------------------------
-------------------
8) copy()----Shallow Copy
------------------------------------------------------------------------------------------------------------------------
-------------------
=>This Function is Used for Copying the content of One Object into another Object ( Implements
Shallow Copy).
=>Syntax: Listobject2=listobj1.copy()
----------------
Examples:
----------------
>>> lst1=[10,"Rossum",34.56]
>>> print(lst1,type(lst1),id(lst1))------[10, 'Rossum', 34.56] <class 'list'> 2302481827584
>>> lst2=lst1.copy() # Shallow Copy
>>> print(lst2,type(lst2),id(lst2))----[10, 'Rossum', 34.56] <class 'list'> 2302481486656
>>> lst1.append("PYTHON")
>>> print(lst1,type(lst1),id(lst1))---[10, 'Rossum', 34.56, 'PYTHON'] <class 'list'> 2302481827584
>>> print(lst2,type(lst2),id(lst2))---[10, 'Rossum', 34.56] <class 'list'> 2302481486656
>>> lst2.append("NL")
>>> print(lst2,type(lst2),id(lst2))--[10, 'Rossum', 34.56, 'NL'] <class 'list'> 2302481486656
>>> print(lst1,type(lst1),id(lst1))--[10, 'Rossum', 34.56, 'PYTHON'] <class 'list'> 2302481827584
-------------------------------
Deep Copy--Examples
---------------------------------
>>> lst1=[10,"Rossum",34.56]
>>> print(lst1,type(lst1),id(lst1))---------[10, 'Rossum', 34.56] <class 'list'> 2302481517760
>>> lst2=lst1 # Deep Copy
>>> print(lst2,type(lst2),id(lst2))---[10, 'Rossum', 34.56] <class 'list'> 2302481517760
>>> lst1.append("HYD")
>>> print(lst1,type(lst1),id(lst1))---[10, 'Rossum', 34.56, 'HYD'] <class 'list'> 2302481517760
>>> print(lst2,type(lst2),id(lst2))---[10, 'Rossum', 34.56, 'HYD'] <class 'list'> 2302481517760
>>> lst2.remove("Rossum")
>>> print(lst1,type(lst1),id(lst1))---[10, 34.56, 'HYD'] <class 'list'> 2302481517760
>>> print(lst2,type(lst2),id(lst2))---[10, 34.56, 'HYD'] <class 'list'> 2302481517760
------------------------------------------------------------------------------------------------------------------------
-------------------
9. count()
------------------------------------------------------------------------------------------------------------------------
-------------------
=>Syntax: listobj1.count(Value)
=>This Function is used for finding / Counting Number of occurences of Specified Value of List
object.
=>If the Specified Value does not exist in list object then we get 0 as a Result.
-----------------------
Examples
-----------------------
>>> lst=[10,20,30,10,20,50,60,70,10]
>>> print(lst)-----------[10, 20, 30, 10, 20, 50, 60, 70, 10]
>>> lst.count(10)-------3
>>> lst.count(20)-------2
>>> lst.count(30)-------1
>>> lst.count(40)-------0
>>> lst.count("PYTHON" )-----0
>>> list().count(10)----------0
>>> [].count(10)-------------0
------------------------------------------------------------------------------------------------------------------------
-------------------
10. reverse()
------------------------------------------------------------------------------------------------------------------------
-------------------
Syntax: listobj.reverse()
=>This Function is used for reversing(Front elements to back and back elements to Front) the
elements
of list object in same list itself.
----------------------
Examples:
---------------------
>>> lst1=[10,"Rossum",34.56,"PYTHON"]
>>> print(lst1,id(lst1))-----------[10, 'Rossum', 34.56, 'PYTHON'] 2302485781376
>>> lst1.reverse()
>>> print(lst1,id(lst1))-----------['PYTHON', 34.56, 'Rossum', 10] 2302485781376
-----------------------
>>> lst2=[10,20,30,100,200,300]
>>> print(lst2,id(lst2))--------[10, 20, 30, 100, 200, 300] 2302485776384
>>> lst2.reverse()
>>> print(lst2,id(lst2))-------[300, 200, 100, 30, 20, 10] 2302485776384
---------------------------------------
>>> lst2=[10,20,30,100,200,300]
>>> lst3=lst2.reverse()
>>> print(lst2,id(lst2))---------[300, 200, 100, 30, 20, 10] 2302481517760
>>> print(lst3)--------------None
>>> list().reverse() # No Output
(OR)
>>> print(list().reverse())--------None

------------------------------------------------------------------------------------------------------------------------
----------------------
11) extend()
------------------------------------------------------------------------------------------------------------------------
----------------------
Syntax: listobj1.extend(listobj2)
=>This Function is used for Merging / Combining The values of listobj2 with ListObj1. Hence
Listobj1
contains Its Own Elements and Elements of listobj2.
Syntax: listobj1=listobj1+ listobj2+ ........+listobj-n
=>By using + Operator also we can Merge OR Combine Multiple elements of list objects
---------------
Examples:
---------------
>>> lst1=[10,20,30,40]
>>> lst2=["Python","Java"]
>>> lst3=["Rossum","Gosling"]
>>> lst1.extend(lst2,lst3)------------TypeError: list.extend() takes exactly one argument (2 given)
#### TO Solve the above Error
>>> lst1.extend(lst2)
>>> lst1.extend(lst3)
>>> print(lst1)-------[10, 20, 30, 40, 'Python', 'Java', 'Rossum', 'Gosling']
------------------------------
OR
------------------------------
>>> lst1=[10,20,30,40]
>>> lst2=["Python","Java"]
>>> lst3=["Rossum","Gosling"]
>>> lst1=lst1+lst2+lst3 # Used + Operartor for Merging
>>> print(lst1)-----[10, 20, 30, 40, 'Python', 'Java', 'Rossum', 'Gosling']
------------------------------------------------------------------------------------------------------------------------
----------------------
12) sort()
------------------------------------------------------------------------------------------------------------------------
----------------------
Syntax1: listobj.sort()----->Sorts the given List data in ASCending Order
Syntax2: listobj.sort(revserse=False)----->Sorts the given List data in ASCending Order
Syntax3: listobj.sort(reverse=True)--->Sort the given List data in DESCending Order
-----------------
Examples:
-----------------
>>> lst=[10,-2,12,56,13,-7,45,6]
>>> print(lst,id(lst))--------[10, -2, 12, 56, 13, -7, 45, 6] 2302485781696
>>> lst.sort()
>>> print(lst,id(lst))------[-7, -2, 6, 10, 12, 13, 45, 56] 2302485781696
>>> #------------------------------------
>>> lst=[10,-2,12,56,13,-7,45,6]
>>> print(lst,id(lst))------------[10, -2, 12, 56, 13, -7, 45, 6] 2302481486656
>>> lst.sort()
>>> print(lst,id(lst))---------[-7, -2, 6, 10, 12, 13, 45, 56] 2302481486656
>>> lst.reverse()
>>> print(lst,id(lst))----------[56, 45, 13, 12, 10, 6, -2, -7] 2302481486656
>>> #-----------------------------------------
>>> lst=[10,-2,12,56,13,-7,45,6]
>>> print(lst,id(lst))----------[10, -2, 12, 56, 13, -7, 45, 6] 2302485781696
>>> lst.sort(reverse=True)
>>> print(lst,id(lst))--------[56, 45, 13, 12, 10, 6, -2, -7] 2302485781696
>>> #------------------------------------------
>>> lst=[10,-2,12,56,13,-7,45,6]
>>> print(lst,id(lst))----------[10, -2, 12, 56, 13, -7, 45, 6] 2302481486656
>>> lst.sort(reverse=False)
>>> print(lst,id(lst))-----------[-7, -2, 6, 10, 12, 13, 45, 56] 2302481486656
>>> #-----------------------------------------------
>>> lst=["Trump","Zaki","Biden","Putin","Rossum","Alen"]
>>> print(lst)----------['Trump', 'Zaki', 'Biden', 'Putin', 'Rossum', 'Alen']
>>> lst.sort(reverse=True)
>>> print(lst)------------['Zaki', 'Trump', 'Rossum', 'Putin', 'Biden', 'Alen']
>>> #-------------------------------------------------
>>> lst=["Trump","Zaki","Biden","Putin","Rossum","Alen"]
>>> print(lst)----------['Trump', 'Zaki', 'Biden', 'Putin', 'Rossum', 'Alen']
>>> lst.sort()
>>> print(lst)-------['Alen', 'Biden', 'Putin', 'Rossum', 'Trump', 'Zaki']
>>> #---------------------------------------------------
>>> lst=[10,"Trump",33.33,2+3j,True]
>>> print(lst)---------[10, 'Trump', 33.33, (2+3j), True]
>>> lst.sort()----------TypeError: '<' not supported between instances of 'str' and 'int'
==================================x====================================
=======

Day – 20
===============================================
Inner or Nested List
===============================================
=>The Process of Defining one list inside of another list is called Inner or Nested List
=>Syntax:- listobj=[ Val1, Val2....[Val11,Val12...Val1n], [Val21,Val22..Val2n...], Val-n ]

=>Here Val1,Val2...Val-n are called Values of Outer List


=>Here Val11,Val12...Val-1n are called Values of one Inner List
=>Here Val21,Val22...Val-2n are called Values of another Inner List
=>In inner list we can perform Both Indexing and Slicing Operations
=>On Inner List, we can apply all pre-defined function of list.

Examples:
---------------------------
>>> lst=[100,"Karthik",[18,16,20],[76,75,66],"OUCET"]
>>> print(lst)-----------------[100, 'Karthik', [18, 16, 20], [76, 75, 66], 'OUCET']
>>> lst[-1]--------------------'OUCET'
>>> lst[-2]------------------------[76, 75, 66]
>>> lst[-3]--------------------------[18, 16, 20]
>>> lst[1]-----------------------------------'Karthik'
>>> lst[0]-----------------------------------100
>>> print(lst[2],type(lst[2]))----------------[18, 16, 20] <class 'list'>
>>> print(lst[-2],type(lst[-2]))-------------[76, 75, 66] <class 'list'>
>>> lst[2][0]------------------------------18
>>> lst[2][1]------------------------------16
>>> lst[2][1]=17
>>> print(lst)-----------------[100, 'Karthik', [18, 17, 20], [76, 75, 66], 'OUCET']
>>> lst[2].append(16)
>>> print(lst)---------------[100, 'Karthik', [18, 17, 20, 16], [76, 75, 66], 'OUCET']
>>> lst[-2].insert(-2,80)
>>> print(lst)--------------[100, 'Karthik', [18, 17, 20, 16], [76, 80, 75, 66], 'OUCET']
>>> del lst[-2]
>>> print(lst)--------------[100, 'Karthik', [18, 17, 20, 16], 'OUCET']
>>> lst[2].clear()
>>> print(lst)----------------[100, 'Karthik', [], 'OUCET']
>>> del lst[2]
>>> print(lst)---------------------[100, 'Karthik', 'OUCET']
>>> lst.insert(2,[16,15,18,17])
>>> print(lst)--------------------------[100, 'Karthik', [16, 15, 18, 17], 'OUCET']
>>> lst.insert(-1,[77,66,78,55])
>>> print(lst)-----------------[100, 'Karthik', [16, 15, 18, 17], [77, 66, 78, 55], 'OUCET']
>>> lst[2].sort()
>>> print(lst)-------------------[100, 'Karthik', [15, 16, 17, 18], [77, 66, 78, 55], 'OUCET']
>>> lst[-2].sort(reverse=True)
>>> print(lst)--------------------[100, 'Karthik', [15, 16, 17, 18], [78, 77, 66, 55], 'OUCET']
------------------
Examples:
------------------
>>> studlist=[100,"DLPrince",[18,16,19],[78,66,79],"OUCET"]

>>> print(studlist,type(studlist))--[100, 'DLPrince', [18, 16, 19], [78, 66, 79], 'OUCET']
<class 'list'>
>>> print(studlist[2],type(studlist[2]))---[18, 16, 19] <class 'list'>
>>> print(studlist[-2],type(studlist[-2]))---[78, 66, 79] <class 'list'>
>>> studlist[-3].append(17)
>>> print(studlist,type(studlist))--[100, 'DLPrince', [18, 16, 19, 17], [78, 66, 79],
'OUCET'] <class 'list'>
>>> studlist[3].append(68)
>>> print(studlist,type(studlist))---[100, 'DLPrince', [18, 16, 19, 17], [78, 66, 79, 68],
'OUCET'] <class 'list'>
>>> studlist[2].sort()
>>> print(studlist,type(studlist))---[100, 'DLPrince', [16, 17, 18, 19], [78, 66, 79, 68],
'OUCET'] <class 'list'>
>>> studlist[3].sort(reverse=True)
>>> print(studlist,type(studlist))----[100, 'DLPrince', [16, 17, 18, 19], [79, 78, 68, 66],
'OUCET'] <class 'list'>
>>> studlist[2].pop(-2)----18
>>> studlist[-2].remove(68)
>>> print(studlist,type(studlist))--[100, 'DLPrince', [16, 17, 19], [79, 78, 66], 'OUCET']
<class 'list'>
>>> studlist[2].clear()
>>> print(studlist,type(studlist))--[100, 'DLPrince', [], [79, 78, 66], 'OUCET'] <class
'list'>
>>> studlist[2].append(14)
>>> print(studlist,type(studlist))---[100, 'DLPrince', [14], [79, 78, 66], 'OUCET'] <class
'list'>
>>> del studlist[2]
>>> del studlist[-2]
>>> print(studlist,type(studlist))---[100, 'DLPrince', 'OUCET'] <class 'list'>
>>> studlist.insert(2,[17,15,14,19])
>>> print(studlist,type(studlist))--[100, 'DLPrince', [17, 15, 14, 19], 'OUCET'] <class
'list'>
>>> studlist.append([66,78,65,76])
>>> print(studlist,type(studlist))---[100, 'DLPrince', [17, 15, 14, 19], 'OUCET', [66, 78,
65, 76]] <class 'list'>
>>> studlist[-2]---'OUCET'
>>> len(studlist)----5
>>> len(studlist[2])---4
>>> len(studlist[-1])---4
===================x==================================

=============================================
tuple
=============================================
Properties
-----------------
=>'tuple' is one of the pre-defined class and treated as list data type
=>The purpose of tuple data type is that " To store Multiple Values either of same Type OR
Different Type OR Both the Types in Single Object with Unique and Duplicate Values".
=>The Values / Elements of tuple must be stored / Organized with Braces ( ) and Values must be
separted by comma.
=>An object of tuple maintains Insertion order.
=>On object of tuple, we can perform Both Indexing and Slicing Operations.
=>An object of tuple belongs to IMMutable
=>W.r.t tuple class, we can create 2 types of tuple objects. They are
a) Empty tuple
b) Non-Empty tuple
--------------------------
a) Empty tuple:
--------------------------
=>An empty tuple is one, which does not contain any Elements and whose length is 0.
=>Syntax: varname=()
(OR)
varname=tuple()
--------------------------
b) Non-Empty tuple:
--------------------------
=>An Non-Empty tuple is one, which contains Elements and whose length is >0.
=>Syntax: varname=(Val1,Val2.....Val-n)
(OR)
=>Syntax: varname=Val1,Val2.....Val-n
(OR)
varname=tuple(object)
------------------------------------------------------------------------------------------------------------------------
----------------------
NOTE: The Functionality of tuple is exactly similar to Functionality of list but list object belongs
to
Mutable and tuple object belongs to Immutable.
------------------------------------------------------------------------------------------------------------------------
----------------------
Examples:
------------------------------------------------------------------------------------------------------------------------
----------------------
>>> t1=(10,20,30,10,50,60,70)
>>> print(t1,type(t1))----------------(10, 20, 30, 10, 50, 60, 70) <class 'tuple'>
>>> t2=(100,"Travis",33.33,"HYD")
>>> print(t2,type(t2))-----------(100, 'Travis', 33.33, 'HYD') <class 'tuple'>
>>> len(t1)-----------7
>>> len(t2)----------4
>>> t3=100,"Rossum",44.44,"PYTHON"
>>> print(t3,type(t3))-----(100, 'Rossum', 44.44, 'PYTHON') <class 'tuple'>
--------------------------------------------
>>> t1=()
>>> print(t1,type(t1))------------() <class 'tuple'>
>>> len(t1)-------------------------0
>>> t2=tuple()
>>> print(t2,type(t2))-----------() <class 'tuple'>
>>> len(t2)------------------------0
--------------------------------------------
>>> t=(100,"Rossum",44.44,"PYTHON")
>>> print(t,type(t),id(t))--------(100, 'Rossum', 44.44, 'PYTHON') <class 'tuple'> 2605398318096
>>> t[0]--------------100
>>> t[1]--------------'Rossum'
>>> t[-1]------------'PYTHON'
>>> t[0]=200-----------TypeError: 'tuple' object does not support item assignment
----------------------------------------------
>>> l1=[100,"Rossum",44.44,"PYTHON"]
>>> print(l1,type(l1))-----------[100, 'Rossum', 44.44, 'PYTHON'] <class 'list'>
>>> t1=tuple(l1)
>>> print(t1,type(t1))----------(100, 'Rossum', 44.44, 'PYTHON') <class 'tuple'>
>>> l2=list(t1)
>>> print(l2,type(l2))----------[100, 'Rossum', 44.44, 'PYTHON'] <class 'list'>
------------------------------------------------------------
>>> t=(100,"Rossum",44.44,"PYTHON")
>>> print(t,type(t))-----------(100, 'Rossum', 44.44, 'PYTHON') <class 'tuple'>
>>> t[0:3]-----------(100, 'Rossum', 44.44)
>>> t[::-1]-------------('PYTHON', 44.44, 'Rossum', 100)
------------------------------------------------------------------------------------------------------------------------
-
Special Points
---------------------------
>>> a=10
>>> t=tuple(a)--------------TypeError: 'int' object is not iterable
>>> t=tuple(a,)-------------TypeError: 'int' object is not iterable
>>> t=tuple((a))-------------TypeError: 'int' object is not iterable
>>> t=tuple([a])
>>> print(t,type(t))--------------(10,) <class 'tuple'>
--------OR-------------
>>> b=100
>>> t=(b,)
>>> print(t,type(t))-----------(100,) <class 'tuple'>
-----------------------------------
>>> b=12.34
>>> t=(b)
>>> print(t,type(t))------------12.34 <class 'float'>
>>> t=(b,)
>>> print(t,type(t))------------(12.34,) <class 'tuple'>
------------------------------------------------------------------------------------------------------------------------
----=============================================
Pre-defined Function in tuple
=============================================
=>We know that on the object of tuple we can perform Both Indexing and Slicing Operations.
=>Along with these operations, we can also perform other operations by using the following
pre-defined Functions.

1)index()
2)count()
-------------------
Examples:
------------------
>>> t1=(10,"RS",45.67)
>>> print(t1,type(t1))------------(10, 'RS', 45.67) <class 'tuple'>
>>> t1.index(10)---------0
>>> t1.index("RS")------1
>>> t1=(10,"RS",45.67)
>>> print(t1,type(t1))-------(10, 'RS', 45.67) <class 'tuple'>
>>> t1.count(10)-------1
>>> t1.count(100)------0
>>> t1=(10,0,10,10,20,0,10)
>>> print(t1,type(t1))---------(10, 0, 10, 10, 20, 0, 10) <class 'tuple'>
>>> t1.count(10)---------------4
>>> t1.count(0)-----------------2
>>> t1.count(100)--------------0
---------------------------
The Functions not present in tuple
---------------------------
append()
insert()
remove()
clear()
pop(index)
pop()
reverse()
sort()
copy()
extend()
---------------------------------------
NOTE:- By Using del Operator we can't delete values of tuple object By using Indexing and
slicing but we can delete entire object
Examples:
---------------
>>> t1=(10,-34,0,10,23,56,76,21)
>>> print(t1,type(t1))--------------(10, -34, 0, 10, 23, 56, 76, 21) <class 'tuple'>
>>> del t1[0]------TypeError: 'tuple' object doesn't support item deletion
>>> del t1[0:4]----TypeError: 'tuple' object does not support item deletion
>>> del t1 # Here we are removing complete object.
>>> print(t1,type(t1))-----NameError: name 't1' is not defined.
========================================================
MOST IMP:
---------------
sorted(): This Function is used for Sorting the data of immutable object tuple and gives
the sorted data in the form of list.
=>Syntax: listobj=sorted(tuple object)

Examples:
--------------------------------------------------------
>>> t1=(10,23,-56,-1,13,15,6,-2)
>>> print(t1,type(t1))------------(10, 23, -56, -1, 13, 15, 6, -2) <class 'tuple'>
>>> t1.sort()----------------------AttributeError: 'tuple' object has no attribute 'sort'
>>> x=sorted(t1)
>>> print(x,type(x))-----------[-56, -2, -1, 6, 10, 13, 15, 23] <class 'list'>
>>> print(t1,type(t1))----------(10, 23, -56, -1, 13, 15, 6, -2) <class 'tuple'>
>>> t1=tuple(x) # Converted sorted list into tuple
>>> print(t1,type(t1))---------(-56, -2, -1, 6, 10, 13, 15, 23) <class 'tuple'>
>>> t2=t1[::-1]
>>> print(t2,type(t2))------(23, 15, 13, 10, 6, -1, -2, -56) <class 'tuple'>
OR
>>> t1=(10,-4,12,34,16,-6,0,15)
>>> print(t1,type(t1))---------------------(10, -4, 12, 34, 16, -6, 0, 15) <class 'tuple'>
>>> l1=list(t1)
>>> print(l1,type(l1))-----------------[10, -4, 12, 34, 16, -6, 0, 15] <class 'list'>
>>> l1.sort()
>>> print(l1,type(l1))-------------------[-6, -4, 0, 10, 12, 15, 16, 34] <class 'list'>
>>> t1=tuple(l1)
>>> print(t1,type(t1))---------------(-6, -4, 0, 10, 12, 15, 16, 34) <class 'tuple'>
>>>t1=t1[::-1]
>>> print(t1,type(t1))----------------(34, 16, 15, 12, 10, 0, -4, -6) <class 'tuple'>
==================x================================

Day – 21

Tuple
=================================================
Inner (OR) Nested tuple
==================================================
=>The Process of Defining One tuple in another tuple is called Inner or Nested tuple
=>Syntax:- tplobj1=( Val1,Val2....(Val11,Val12....Val1n).....(Val21,Val22...Val2n)..........Val-n )

=>Here (Val11,Val12....Val1n) is called One Inner OR Nested tuple


(Val21,Val22...Val2n) is called another Inner OR Nested tuple
=> ( Val1,Val2....(Val11,Val12....Val1n).....(Val21,Val22...Val2n)....Val-n ) is called Outer tuple
=>All the pre-defined Functions of tuple can be applied on Inner or Nested tuple.
=>On Inner or Nested tuple we can perform Index and Slicing Operations.
----------------------------------------------------------------------------------------------------------
Examples:
----------------------------------------------------------------------------------------------------------
>>> sf=(10,"RS",(17,18,16),(78,66,79),"OUCET")
>>> print(sf,type(sf))------------(10, 'RS', (17, 18, 16), (78, 66, 79), 'OUCET') <class 'tuple'>
>>> print(sf[0])-----10
>>> print(sf[2],type(sf[2]),type(sf))---------(17, 18, 16) <class 'tuple'> <class 'tuple'>
>>> print(sf[0:3])------------(10, 'RS', (17, 18, 16))
---------------------------------------------------------------------------
>>> sf=(10,"RS",[17,18,16],(78,66,79),"OUCET")
>>> print(sf,type(sf))----------------(10, 'RS', [17, 18, 16], (78, 66, 79), 'OUCET') <class 'tuple'>
>>> print(sf[2],type(sf[2]),type(sf))------------[17, 18, 16] <class 'list'> <class 'tuple'>
>>> sf[2].append(12)
>>> print(sf[2],type(sf[2]),type(sf))------------[17, 18, 16, 12] <class 'list'> <class 'tuple'>
>>> print(sf,type(sf))---------(10, 'RS', [17, 18, 16, 12], (78, 66, 79), 'OUCET') <class 'tuple'>
>>> sf[3].append(12)---AttributeError: 'tuple' object has no attribute 'append'
-------------------------------------------------------
>>> sf=[10,"RS",[17,18,16],(78,66,79),"OUCET"]
>>> print(sf,type(sf))-------------[10, 'RS', [17, 18, 16], (78, 66, 79), 'OUCET'] <class 'list'>
>>> print(sf[2],type(sf[2]),type(sf))--------[17, 18, 16] <class 'list'> <class 'list'>
>>> print(sf[3],type(sf[3]),type(sf))-------(78, 66, 79) <class 'tuple'> <class 'list'>
-----------------------------------------------------------------------------------------------------------
NOTE:
--------
=>One can define One List in another List
=>One can define One Tuple in another Tuple
=>One can define One List in another Tuple ( tuple of lists)
=>One can define One tuple in another List (list of tuples)
---------------------------------------------------------------------------------------------------------
>>> print(t1,type(t1))
(10, 'Rossum', [16, 18, 17], ('CSE', 'AI', 'DS'), 'OUCET') <class 'tuple'>
>>> print(t1[2],type(t1[2]))-------[16, 18, 17] <class 'list'>
>>> print(t1[3],type(t1[3]))------('CSE', 'AI', 'DS') <class 'tuple'>
>>> t1[2].append("KVR")
>>> print(t1,type(t1))--(10, 'Rossum', [16, 18, 17, 'KVR'], ('CSE', 'AI', 'DS'), 'OUCET') <class
'tuple'>
>>> t1[3].append("Python")-----AttributeError: 'tuple' object has no attribute 'append'
>>> t1[2][1]--------18
>>> t1[2][-2]------17
>>> t1[2][-3]------18
>>> k=sorted(t1[-2])
>>> k------------['AI', 'CSE', 'DS']
>>> t1[3]=k---------TypeError: 'tuple' object does not support item assignment
>>> l1=list(t1)----
>>> l1----------[10, 'Rossum', [16, 18, 17, 'KVR'], ('CSE', 'AI', 'DS'), 'OUCET']
>>> l1[3]=k
>>> l1-----[10, 'Rossum', [16, 18, 17, 'KVR'], ['AI', 'CSE', 'DS'], 'OUCET']
>>> y=tuple(l1[3])
>>> l1[3]=y
>>> l1-----[10, 'Rossum', [16, 18, 17, 'KVR'], ('AI', 'CSE', 'DS'), 'OUCET']
>>> t2=tuple(l1)
>>> t2-----(10, 'Rossum', [16, 18, 17, 'KVR'], ('AI', 'CSE', 'DS'), 'OUCET')
-------------------------------
>>> t1=('AI', 'cSE', 'DS')
>>> k=sorted(t1)
>>> k-------['AI', 'DS', 'cSE']

=========================================================
Set Category Data Types (Collection or Data Structures)
=========================================================
=>The purpose of Set Category Data Types is that " To store Multiple Values either of Same Type
or Different Type or Both the Types in Single Object with Unique Values (No Duplicates are
allowed)."
=>We have 2 data type in Set Category. They are

1. set (mutable and immutable)


2. frozenset (immutable)
================================x======================================
=======
===========================================
1. set
==========================================
Properties
------------------
=>'set' is one of the Pre-defined class and treated as set data type.
=>The purpose of set data type is that " To store Multiple Values either of Same Type or Different
Type or
Both the Types in Single Object with Unique Values (No Duplicates are allowed).
=>The Elements of set must be stored within Curly Braces { } and the elements must be separated
by
comma.
=>An object of set does not maintain Insertion Order bcoz PVM displays any possibility of set
elements.
=>On the object set, we can't perform Both Indexing and Slicing Operations bcoz set never
maintains
Insertion order.
=>An object of set belongs to Both Mutable in the case of Add and immutable in the case of Item
Assigment.
=>w.r.t set , we can create Two Types of set objects. They are
a) Empty Set
b) Non-Empty Set
----------------------------------
a) Empty Set
----------------------------------
=>An Empty Set is One, which does not contain any Elements and whose length is 0
=>Syntax: varname=set()
-------------------------------------------
b) Non-Empty Set
-------------------------------------------
=>An Nn-Empty Set is One, which contains Elements and whose length is>0
=>Syntax1: varname={Val1,Val2,...Val-n}
=>Syntax2: varname=set(object)
======================================x================================
===
Examples
------------------------------------------------------------------------------------------------------------------------
--------
>>> s1={10,20,30,40,10,50,60,20}
>>> print(s1,type(s1))---------------{50, 20, 40, 10, 60, 30} <class 'set'>
>>> print(s1,type(s1))--------------{50, 20, 40, 10, 60, 30} <class 'set'>
>>> s2={10,"Travis",44.44,True,"Numpy"}
>>> print(s2,type(s2))-----------{'Numpy', True, 'Travis', 10, 44.44} <class 'set'>
----------------------
>>> s2={10,"Travis",44.44,True,"Numpy"}
>>> print(s2,type(s2))-----------{'Numpy', True, 'Travis', 10, 44.44} <class 'set'>
>>> s2[0]----------------TypeError: 'set' object is not subscriptable
>>> s2[0:3]---------------TypeError: 'set' object is not subscriptable
----------------------------------------
>>> s2={10,"Travis",44.44,True,"Numpy"}
>>> print(s2,type(s2))----------{'Numpy', True, 'Travis', 10, 44.44} <class 'set'>
>>> s2[0]=100-------------TypeError: 'set' object does not support item assignment--IMMUTABLE
------------------------------------------------
>>> s2={10,"Travis",44.44,True,"Numpy"}
>>> print(s2,type(s2),id(s2))-------------{'Numpy', True, 'Travis', 10, 44.44} <class 'set'>
2485370854016
>>> s2.add("HYD") # MUTABLE
>>> print(s2,type(s2),id(s2))----{'Numpy', True, 'Travis', 10, 44.44, 'HYD'} <class 'set'>
2485370854016
------------------------------
>>> x={}
>>> print(x,type(x))--------------{} <class 'dict'>
>>> s=set()
>>> print(s,type(s),len(s))---------- set() <class 'set'> 0
------------------------------------
>>> l1=[10,20,30,10]
>>> print(l1,type(l1))-------------[10, 20, 30, 10] <class 'list'>
>>> s1=set(l1)
>>> print(s1,type(s1))------------{10, 20, 30} <class 'set'>
-----------------------------------
>>> s="MISSISSIPPI"
>>> s1=set(s)
>>> print(s1)-------------------{'M', 'S', 'P', 'I'}
=======================================x===============================
====

==================================================
Pre-Functions in set
===================================================
=>On the object of set, we can perform different type of Operations by using Functions present in
ste object. They are

1. clear()
2. add()
3. remove()
4. discard()
5. pop()
------------;
6. isdisjoint()
7. issubset()
8. issuperset()
9. union()
10. intersectrion()
11. difference()
12. symmetric_differenece()
13. update()
--------
1) clear()
------------------------------------------------------------------------------------------------------------------------
--------
=>Syntax: setobj.clear()
=>This Function is used for Removing all the values of set object.
Examples:
-------------------
>>> s1={10,20,30,40,50,10}
>>> print(s1,type(s1),id(s1))----------{50, 20, 40, 10, 30} <class 'set'> 2485370854240
>>> s1.clear()
>>> print(s1,type(s1),id(s1))--------set() <class 'set'> 2485370854240
------------------------------------
>>> print(s1,len(s1))----------set() 0
>>> s1.clear()---------------- No Output
>>> print(s1.clear())----------None
------------------------------------------------------------------------------------------------------------------------
--------
2) add()
------------------------------------------------------------------------------------------------------------------------
--------
Syntax: setobj.add(Value)
=>This Function is used for adding the values to set object.
Examples:
--------------------
>>> s1={10,"Rossum",34.56,"HYD"}
>>> print(s1,type(s1),id(s1))--------{10, 'Rossum', 34.56, 'HYD'} <class 'set'> 2485370853568
>>> s1.add("NL")
>>> print(s1,type(s1),id(s1))-------{34.56, 'Rossum', 'NL', 10, 'HYD'} <class 'set'> 2485370853568
>>> s1.add(True)
>>> s1.add(2+3j)
>>> print(s1,type(s1),id(s1))-----{True, 34.56, 'Rossum', 'NL', 10, (2+3j), 'HYD'} <class 'set'>
2485370853568
--------------------------------------
>>> s1=set()
>>> print(s1,type(s1),id(s1))------------set() <class 'set'> 2485370854240
>>> s1.add(100)
>>> s1.add("Naresh")
>>> s1.add(12345)
>>> s1.add("Python")
>>> print(s1,type(s1),id(s1))-----{'Naresh', 12345, 'Python', 100} <class 'set'> 2485370854240
------------------------------------------------------------------------------------------------------------------------
--------
3) remove()
------------------------------------------------------------------------------------------------------------------------
--------
Syntax: setobj.remove(Value)
=>This Function is used for removing the values of setobject.
=>if the specified Values does not exist in set object then we get KeyError
-----------------------
Examples:
-----------------------
>>> s1={10,"Rossum",34.56,"HYD"}
>>> print(s1,id(s1))----------{10, 'Rossum', 34.56, 'HYD'} 2485370853568
>>> s1.remove(10)
>>> print(s1,id(s1))-----------{'Rossum', 34.56, 'HYD'} 2485370853568
>>> s1.remove("HYD")
>>> print(s1,id(s1))------------{'Rossum', 34.56} 2485370853568
>>> s1.remove("BANG")-------------KeyError: 'BANG'
>>> set().remove(100)---------------KeyError: 100

Day – 22

4) discard()
------------------------------------------------------------------------------------------------------------------------
--------
Syntax: setobj.discard(Value)
=>This Function is used for Removing the Vaue from setobject.
=>If the Specified Value does not exist then we never get any Error
------------------
Examples:
------------------
>>> s1={10,"Ankit",34.56,"Python","HYD"}
>>> print(s1,type(s1),id(s1))-----------{'Ankit', 34.56, 'HYD', 10, 'Python'} <class 'set'>
2705097791904
>>> s1.discard(10)
>>> print(s1,type(s1),id(s1))-------{'Ankit', 34.56, 'HYD', 'Python'} <class 'set'> 2705097791904
>>> s1.discard("HYD")
>>> print(s1,type(s1),id(s1))-------{'Ankit', 34.56, 'Python'} <class 'set'> 2705097791904
>>> s1.discard("Python")
>>> print(s1,type(s1),id(s1))---------{'Ankit', 34.56} <class 'set'> 2705097791904
>>> s1.discard(1000) # we wont' get KeyError
>>> print(s1,type(s1),id(s1))--------{'Ankit', 34.56} <class 'set'> 2705097791904
>>> s1.remove(1000)KeyError: 1000
------------------------------------------------------------------------------------------------------------------------
---------------
5) pop()
------------------------------------------------------------------------------------------------------------------------
---------------
Syntax: setobj.pop()
=>This Function is used for Removing Any Arbitrary Element from non-empty set object
=>When we call pop() upon empty set object then we get KeyError
-----------------
Example-1 ---set elemements are given and order of display not shown and pop() removes Arbitrary
Element always
-----------------
>>> s1={10,"Ankit",34.56,"Python","HYD"}
>>> s1.pop()--------------'Ankit'
>>> s1.pop()-------------34.56
>>> s1.pop()-------------'HYD'
>>> s1.pop()-------------10
>>> s1.pop()------------'Python'
>>> print(s1)------------set()
>>> s1.pop()----------KeyError: 'pop from an empty set'
>>> set().pop()-------KeyError: 'pop from an empty set'
--------------------------------------------------------------------------------
Example-2: set elemements are given and order of disply shown and pop() removes First Element
always
--------------------------------------------------------------------------------
>>> s1={100,200,300,150,450,-120}
>>> print(s1,id(s1))--------------{450, 100, -120, 150, 200, 300} 2705097791232
>>> s1.pop()-----------450
>>> s1.pop()-----------100
>>> s1.pop()------------120
>>> s1.pop()-----------150
>>> s1.pop()-----------200
>>> s1.pop()-----------300
>>> print(s1,id(s1))--------set() 2705097791232
>>> s1.pop()---------------------KeyError: 'pop from an empty set'
------------------------------------------------------------------------------------------------------------------------
-----------
6) isdisjoint()
------------------------------------------------------------------------------------------------------------------------
-----------
=>Syntax: setobj1.isdisjoint(setobj2)
=>This Function Returns True Provided There is No Common Element in setobj1 and setobj2.
=>This Function Returns False Provided There is atleast one Common Element in setobj1 and
setobj2.
-------------------
Examples:
-------------------
>>> s1={10,20,30,40}
>>> s2={15,25,35}
>>> s3={10,100,200,300}
>>> s1.isdisjoint(s2)---------------True
>>> s1.isdisjoint(s3)---------------False
>>> s2.isdisjoint(s3)---------------True
------------------------------------------------------------------------------------------------------------------------
-----------
7) issubset()
------------------------------------------------------------------------------------------------------------------------
-----------
=>Syntax: setobj1.issubset(setobj2)
=>This function returns True Provided All the elements of setobj1 present in setobj2 (OR) setobj2
contains all the elements of setobj1
=>This function returns False Provided atleast one element of setobj1 not present in setobj2 (OR)
setobj2 not containing atleast one element of setobj1.
Examples:
---------------------
>>> s1={0,1,2,3,4,5,6,7,8,9}
>>> s2={3,4,5}
>>> s3={10,20,30}
>>> s2.issubset(s1)-----------True
>>> s3.issubset(s1)-----------False
>>> s1.issubset(s3)------------False
>>> s4={1,15,25}
>>> s4.issubset(s1)--------False
>>> s4={1,2,3,10}
>>> s4.issubset(s1)-------False
------------------------------------------------------------------------------------------------------------------------
-----------
8) issuperset()
------------------------------------------------------------------------------------------------------------------------
-----------
=>Syntax: setobj1.issuperset(setobj2)
=>This function returns True Provided setobj1 contains all the elements of setobj2 (OR) all
elements of setobj2 present in setobj1
=>This function returns False Provided atleast one element of setobj2 not present in setobj1 (OR)
setobj1 not containing atleast one element of setobj2.
-------------------
Examples:
-------------------
>>> s1={0,1,2,3,4,5,6,7,8,9}
>>> s2={3,4,5}
>>> s3={10,20,30}
>>> s1.issuperset(s2)----------True
>>> s1.issuperset(s3)----------False
>>> s4={1,2,3,10}
>>> s1.issuperset(s4)----------False
------------------------------------------------------------------------------------------------------------------------
-----------
9) union()
------------------------------------------------------------------------------------------------------------------------
-----------
=>Syntax: setobj3=setobj1.union(setobj2)
(OR)
=>Syntax: setobj3=setobj2.union(setobj1)
=>This Function is used for Taking all Unique Elements of setobj1 and setobj2 and place them in
setobj3.
---------------------
Examples:
--------------------
>>> cp={"Sachin","Rohit","Kohli"}
>>> tp={"Kohli","Rossum","Travis"}
>>> print(cp,type(cp))------------{'Sachin', 'Kohli', 'Rohit'} <class 'set'>
>>> print(tp,type(tp))-------------{'Rossum', 'Travis', 'Kohli'} <class 'set'>
>>> allcptp=cp.union(tp)
>>> print(allcptp,type(allcptp))----{'Sachin', 'Kohli', 'Rohit', 'Rossum', 'Travis'} <class 'set'>
(OR)
>>> allcptp=tp.union(cp)
>>> print(allcptp,type(allcptp))---{'Sachin', 'Kohli', 'Rohit', 'Rossum', 'Travis'} <class 'set'>
------------------------------------------------------------------------------------------------------------------------
-----------
10) intersection()
------------------------------------------------------------------------------------------------------------------------
-----------
=>Syntax: setobj3=setobj1.intersection(setobj2)
(OR)
=>Syntax: setobj3=setobj2.intersection(setobj1)
=>This Function is used for Taking Common Elements of setobj1 and setobj2 and place them in
setobj3.
--------------------------
Examples
--------------------------
>>> cp={"Sachin","Rohit","Kohli"}
>>> tp={"Kohli","Rossum","Travis"}
>>> print(cp,type(cp))-----------------{'Sachin', 'Kohli', 'Rohit'} <class 'set'>
>>> print(tp,type(tp))------------------{'Rossum', 'Travis', 'Kohli'} <class 'set'>
>>> bothcptp=cp.intersection(tp)
>>> print(bothcptp,type(bothcptp))--------{'Kohli'} <class 'set'>
OR
>>> bothcptp=tp.intersection(cp)
>>> print(bothcptp,type(bothcptp))-------{'Kohli'} <class 'set'>
--------------------------
>>> a={10,20}
>>> b={30,40}
>>> a.intersection(b)----------set()
>>> {10,20,30}.intersection({'a','e','i','o','u'})-----------set()
>>> {10,20,30}.intersection({'a','e','i','o','u',10})---------{10}
------------------------------------------------------------------------------------------------------------------------
-----------
11) difference()
------------------------------------------------------------------------------------------------------------------------
-----------
Syntax1: setobj3=setobj1.difference(setobj2)
-------------
=>This Function Removes the common Elements from setobj1 and setobj2 and It takes Remaining
Elements from setobj1 and placed in setobj3.
----------------
Examples:
----------------
>>> cp={"Sachin","Rohit","Kohli"}
>>> tp={"Kohli","Rossum","Travis"}
>>> print(cp,type(cp))-----------------{'Sachin', 'Kohli', 'Rohit'} <class 'set'>
>>> print(tp,type(tp))------------------{'Rossum', 'Travis', 'Kohli'} <class 'set'>
>>> onlycp=cp.difference(tp)
>>> print(onlycp,type(onlycp))-------{'Sachin', 'Rohit'} <class 'set'>
------------------------------------------
Syntax2: setobj3=setobj2.difference(setobj1)
-------------
=>This Function Removes the common Elements from setobj2 and setobj1 and It takes Remaining
Elements from setobj2 and placed in setobj3.
----------------
Examples:
----------------
>>> cp={"Sachin","Rohit","Kohli"}
>>> tp={"Kohli","Rossum","Travis"}
>>> print(cp,type(cp))-----------------{'Sachin', 'Kohli', 'Rohit'} <class 'set'>
>>> print(tp,type(tp))------------------{'Rossum', 'Travis', 'Kohli'} <class 'set'>
>>> onlytp=tp.difference(cp)
>>> print(onlytp,type(onlytp))-----------{'Rossum', 'Travis'} <class 'set'>
------------------
>>> a={10,20}
>>> b={10,30,40,20}
>>> a.difference(b)-----------set()
>>> b.difference(a)-----------{40, 30}
------------------------------------------------------------------------------------------------------------------------
-----------
12) symmetric_difference()
------------------------------------------------------------------------------------------------------------------------
-----------
Syntax: setobj3=setobj1.symmetric_difference(setobj2)
(OR)
Syntax: setobj3=setobj2.symmetric_difference(setobj1)

=>This Function Removes the common Elements from setobj1 and setobj2 and It takes Remaining
Elements from both setobj1 and setobj2 and place them in setobj3.

--------------------------
Examples
--------------------------
>>> cp={"Sachin","Rohit","Kohli"}
>>> tp={"Kohli","Rossum","Travis"}
>>> print(cp,type(cp))--------------{'Sachin', 'Kohli', 'Rohit'} <class 'set'>
>>> print(tp,type(tp))---------------{'Rossum', 'Travis', 'Kohli'} <class 'set'>
>>> exclcptp=cp.symmetric_difference(tp)
>>> print(exclcptp,type(exclcptp))---------{'Rohit', 'Travis', 'Sachin', 'Rossum'} <class 'set'>
>>> exclcptp=tp.symmetric_difference(cp)
>>> print(exclcptp,type(exclcptp))----------{'Rohit', 'Travis', 'Sachin', 'Rossum'} <class 'set'>
OR
>>> exclcptp=tp.symmetric_difference(cp)
>>> print(exclcptp)------------{'Rohit', 'Travis', 'Sachin', 'Rossum'}
(OR)
>>> exclcptp=cp.union(tp).difference(cp.intersection(tp))
>>> print(exclcptp)-------{'Rossum', 'Sachin', 'Travis', 'Rohit'}
----------------------
Special Points
----------------------
>>> s1={10,20,30,40}
>>> s2={10,20,50,60}
>>> s3=s1.difference(s2)
>>> print(s3)------------{40, 30}
>>> s4=s2.difference(s1)
>>> print(s4)---------{50, 60}
>>> s5=s1.symmetric_difference(s2)
>>> print(s5)---------{40, 50, 60, 30}
(OR)
>>> s6=s1.union(s2).difference(s1.intersection(s2))
>>> print(s6)-----------{40, 50, 60, 30}
(OR)
>>> s7=s1.difference(s2).union(s2.difference(s1))
>>> print(s7)------------{40, 50, 60, 30}
=====================================================================
MOST IMP---Perform the above Set Operations without set Functions by Using Bitwise Operators
----------------------------------------------------
>>> cp={"Sachin","Rohit","Kohli"}
>>> tp={"Kohli","Rossum","Travis"}
>>> print(cp,type(cp))--------------{'Sachin', 'Kohli', 'Rohit'} <class 'set'>
>>> print(tp,type(tp))---------------{'Rossum', 'Travis', 'Kohli'} <class 'set'>
>>> allcptp=cp|tp # Bitwise OR Operator OR union()
>>> print(allcptp)-----------{'Sachin', 'Kohli', 'Rohit', 'Rossum', 'Travis'}
>>> botcptp=cp&tp # Bitwise AND Operator OR intersection()
>>> print(bothcptp)-----{'Kohli'}
>>> onlycp=cp-tp # - Operator OR difference()
>>> print(onlycp,type(onlycp))------------{'Sachin', 'Rohit'} <class 'set'>
>>> onlytp=tp-cp
>>> print(onlytp,type(onlytp))-------------{'Rossum', 'Travis'} <class 'set'>
>>> exclcptp=cp^tp # Bitwise XOR Operator OR symmetric_difference()
>>> print(exclcptp,type(exclcptp))-------{'Rohit', 'Travis', 'Sachin', 'Rossum'} <class 'set'>
------------------------------------------------------------------------------------------------------------------------
-----------
13) update()
------------------------------------------------------------------------------------------------------------------------
-----------
=>Syntax: setobj1.update(setobj2)
=>This Function is used Merging setobj2 values with setobj1
----------------------
Examples:
---------------------
>>> s1={10,20,30,40}
>>> s2={"Python","Java"}
>>> print(s1,type(s1))--------{40, 10, 20, 30} <class 'set'>
>>> print(s2,type(s2))--------{'Python', 'Java'} <class 'set'>
>>> s1.update(s2)
>>> print(s1)-----------------{20, 40, 10, 'Python', 'Java', 30}
--------------------------
>>> s1={10,20,30,40}
>>> s2={"Python","Java",10}
>>> s1.update(s2)
>>> print(s1)------------------{20, 40, 10, 'Python', 'Java', 30}
=================================x=====================================
====

Day – 23

set part 2

Most imp points


1. set in set------ not
2. set in tuple ------ possible
3. set in list ------- possible
4. list in set --- not
5. tuple in set ------ possible
6. tuple in list -----possible
7. s in s – not
8. set in tup – pos
9. s in t – poss
10. l in s – not

==============================================
Nested or Inner Properties of Set
===============================================
=>We can define

a) Defining set inside of another set NOT POSSIBLE


b) Defining set inside of another Tuple POSSIBLE
c) Defining set inside of another List POSSIBLE
d) Defining tuple inside of Another Set POSSIBLE
e) Defining list inside of another set NOT POSSIBLE

----------------------
Examples:
----------------------
>>> s1={10,"Rossum",{10,15,16},"OUCET"}-----TypeError: unhashable type: 'set'
>>> s1={10,"Rossum",[10,15,16],"OUCET"}----TypeError: unhashable type: 'list'
>>> s1={10,"Rossum",(10,15,16),"OUCET"}-----Valid
>>> print(s1,type(s1))----{'Rossum', 10, 'OUCET', (10, 15, 16)} <class 'set'>
--------------------
>>> t1=(10,"Rossum",{10,15,16},"OUCET")
>>> print(t1[2],type(t1[2]),type(t1))----{16, 10, 15} <class 'set'> <class 'tuple'>
>>> l1=[10,"Rossum",{10,15,16},"OUCET"]
>>> print(l1[2],type(l1[2]),type(l1))----{16, 10, 15} <class 'set'> <class 'list'>
====================================x==================================
=======

==================================================
frozenset
==================================================
Properties
----------------
=>'frozenset' is one of the Pre-defined class and treated as set data type.
=>The purpose of frozenset data type is that " To store Multiple Values either of Same Type or
Different Type or Both the Types in Single Object with Unique Values (No Duplicates are allowed).
=>The Elements of frozenset set must be obtained from list,tuple and set by using a Type casting
Function fronset()
=>An object of frozenset does not maintain Insertion Order bcoz PVM displays any possibility of
frozenset elements.
=>On the object frozenset, we can't perform Both Indexing and Slicing Operations bcoz frozenset
never maintains Insertion order.
=>An object of frozenset belongs to immutable in the case of Item Assigment. and no functions
are allowed to modify/ update the values of frozenset object.
=>w.r.t frozenset , we can create Two Types of frozenset objects. They are
a) Empty frozenset
b) Non-Empty frozenset
----------------------------------
a) Empty frozenset
----------------------------------
=>An Empty frozenset is One, which does not contain any Elements and whose length is 0
=>Syntax: varname=frozenset()
-------------------------------------------
b) Non-Empty frozenSet
-------------------------------------------
=>An Nn-Empty Set is One, which contains Elements and whose length is > 0
=>Syntax1: varname=frozenset( [val1,val2...val-n])
(OR)
=>Syntax2: varname=frozenset( (val1,val2...val-n) )
(OR)
=>Syntax3: varname=frozenset( {val1,val2...val-n})
------------------------------------------------------------------------------------------------------------------------
-----------------------
NOTE:- The functionality of frozenset is exactly similar to set type but an object of set belongs to
Both
Mutable(in the case add() and other Functions) and Immutable (in the case of Item
Assignment), where as an object of frozenset belongs to Immutable bcoz Item Assigment does not
support and No Functions are allowed which are modifying the values of frozenset.
------------------------------------------------------------------------------------------------------------------------
-----------------------
Examples:
------------------------------------------------------------------------------------------------------------------------
-------------------------
>>> fs=frozenset()
>>> print(fs,type(fs),len(fs))---------frozenset() <class 'frozenset'> 0
>>> fs=frozenset([10,20,10,10,10,10])
>>> print(fs,type(fs),len(fs))---------frozenset({10, 20}) <class 'frozenset'> 2
>>> fs=frozenset((10,20,10,10,10,10))
>>> print(fs,type(fs),len(fs))-------------frozenset({10, 20}) <class 'frozenset'> 2
>>> fs=frozenset({10,20,10,10,10,10})
>>> print(fs,type(fs),len(fs))--------------frozenset({10, 20}) <class 'frozenset'> 2
--------------------------------------------------------
>>> fs=frozenset([10,"Travis",45.67,True])
>>> print(fs,type(fs))----------------frozenset({True, 10, 45.67, 'Travis'}) <class 'frozenset'>
>>> fs[0]------------------------------------TypeError: 'frozenset' object is not subscriptable
>>> fs[0:2]----------------------------------TypeError: 'frozenset' object is not subscriptable
>>> fs[0]=100-----------------TypeError: 'frozenset' object does not support item assignment
>>> fs.add(100)--------------AttributeError: 'frozenset' object has no attribute 'add'
================================x======================================
=========
'=====================================
Pre-Defined Functions in frozenset
=====================================
=>frozenset contains the following Functions
a) copy()
b) isdisjoint()
c) issuperset()
d) issubset()
e) union()
f) intersection()
g) difference()
h) symmertic_difference()
NOTE:
-------------
>>> fs1=frozenset({10,20,30,409})
>>> print(fs1,type(fs1),id(fs1))--------frozenset({409, 10, 20, 30}) <class 'frozenset'>

2068835340960
>>> fs2=fs1.copy()
>>> print(fs2,type(fs2),id(fs2))-----frozenset({409, 10, 20, 30}) <class 'frozenset'>

2068835340960

=>In General, Immutable Object content is Not Possible to copy( in the case of tuple). Where as in
the case of frozenset, we are able to copy its content to another frozenset object. Here Original
frozenset object and copied frozenset object contains Same Address and Not at all possible to
Modify / Change their content.
-------------------
Examples:
-----------------
>>> s1={10,"RS",3.4,"PYTHON"}
>>> fs1=frozenset(s1)
>>> print(fs1,type(fs1),id(fs1))---------frozenset({10, 3.4, 'RS', 'PYTHON'}) <class 'frozenset'>
1774317640096
>>> fs2=fs1.copy()
>>> print(fs2,type(fs2),id(fs2))-------frozenset({10, 3.4, 'RS', 'PYTHON'}) <class 'frozenset'>
1774317640096

=>frozenset does not contain the following Functions


a) clear()
b) add()
c) remove()
d) discard()
e) pop()
f) update()
=========================================x=============================
============

====================================================
V) Dict Categeory Data Types ( Collection Data Types or Data Structures)
=====================================================
Properties
---------------------------
=>'dict' is one of the pre-defined class and treated as Dict Data Type.
=>The purpose of dict data type is that "To store (Key,value) in single variable"
=>In (Key,Value), the values of Key is Unique and Values of Value may or may not be unique.
=>The (Key,value) must be organized or stored in the object of dict within Curly Braces {} and
they separated by comma.
=>An object of dict does not support Indexing and Slicing bcoz Values of Key itself considered as
Indices.
=>In the object of dict, Values of Key are treated as Immutable and Values of Value are treated as
mutable.
=>Originally an object of dict is mutable bcoz we can add (Key,Value) externally.
=>We have two types of dict objects. They are
a) Empty dict
b) Non-empty dict
-------------------------
a) Empty dict
-------------------------
=>Empty dict is one, which does not contain any (Key,Value) and whose length is 0
=>Syntax:- dictobj1= { }
or
dictobj=dict()

=>Syntax for adding (Key,Value) to empty dict:


----------------------------------------------------------------
dictobj[Key1]=Val1
dictobj[Key2]=Val2
---------------------------
dictobj[Key-n]=Val-n
Here Key1,Key2...Key-n are called Values of Key and They must be Unique
Here Val1, Val2...Val-n are called Values of Value and They may or may not be unique.
-----------------------------------------------------------------------------------------------------------------------
b) Non-Empty dict
-----------------------------
=>Non-Empty dict is one, which contains (Key,Value) and whose length is >0
=>Syntax:- dictobj1= { Key1:Val1,Key2:Val2......Key-n:Valn}

Here Key1,Key2...Key-n are called Values of Key and They must be Unique
Here Val1, Val2...Val-n are called Values of Value and They may or may not be unique.
=================================================================
Examples:
-----------------
>>> d1={10:"Python",20:"Data Sci",30:"Django"}
>>> print(d1,type(d1))----------{10: 'Python', 20: 'Data Sci', 30: 'Django'} <class 'dict'>
>>> d2={10:3.4,20:4.5,30:5.6,40:3.4}
>>> print(d2,type(d2))------------{10: 3.4, 20: 4.5, 30: 5.6, 40: 3.4} <class 'dict'>
>>> len(d1)--------------3
>>> len(d2)------------4
-------------------------------------------------
>>> d3={}
>>> print(d3,type(d3))------------{} <class 'dict'>
>>> len(d3)-------------0
>>> d4=dict()
>>> print(d4,type(d4))-------------{} <class 'dict'>
>>> len(d4)---------------0
------------------------------------------------------------------------
>>> d2={10:3.4,20:4.5,30:5.6,40:3.4}
>>> print(d2)----------------------------------{10: 3.4, 20: 4.5, 30: 5.6, 40: 3.4}
>>> d2[0]----------------------------------------KeyError: 0
>>> d2[10]-------------------------------------3.4
>>> d2[10]=10.44
>>> print(d2)-------------------------------{10: 10.44, 20: 4.5, 30: 5.6, 40: 3.4}
-------------------------------------------------------------------------------------
>>> d2={10:3.4,20:4.5,30:5.6,40:3.4}
>>> print(d2,type(d2),id(d2))----{10: 3.4, 20: 4.5, 30: 5.6, 40: 3.4} <class 'dict'> 2090750380736
>>> d2[50]=5.5
>>> print(d2,type(d2),id(d2))---{10: 3.4, 20: 4.5, 30: 5.6, 40: 3.4, 50: 5.5} <class 'dict'>

2090750380736
------------------------------------------------------------------------------------------------------------------------
-
>>> d3={}
>>> print(d3,type(d3),id(d3))-------------------{} <class 'dict'> 2090750332992
>>> d3["Python"]=1
>>> d3["Java"]=3
>>> d3["C"]=2
>>> d3["GO"]=1
>>> print(d3,type(d3),id(d3))-----{'Python': 1, 'Java': 3, 'C': 2, 'GO': 1} <class 'dict'>

2090750332992
-------------------------------------------------------------------------------------------------------
>>> d4=dict()
>>> print(d4,type(d4),id(d4))---------------{} <class 'dict'> 2090754532032
>>> d4[10]="Apple"
>>> d4[20]="Mango"
>>> d4[30]="Kiwi"
>>> d4[40]="Sberry"
>>> d4[50]="Orange"
>>> print(d4,type(d4),id(d4))---{10: 'Apple', 20: 'Mango', 30: 'Kiwi', 40: 'Sberry', 50: 'Orange'}
<class 'dict'> 2090754532032
>>> d4[10]="Guava"
>>> print(d4,type(d4),id(d4))----{10: 'Guava', 20: 'Mango', 30: 'Kiwi', 40: 'Sberry', 50: 'Orange'}
<class 'dict'> 2090754532032
--------------------------------------------------------------------------------------
>>> d2={10:3.4,20:4.5,30:5.6,40:3.4}
>>> print(d2,type(d2),id(d2))---{10: 3.4, 20: 4.5, 30: 5.6, 40: 3.4} <class 'dict'> 2090754531520
>>> d2[50]=1.2
>>> print(d2,type(d2),id(d2))---{10: 3.4, 20: 4.5, 30: 5.6, 40: 3.4, 50: 1.2} <class 'dict'>
2090754531520

Day – 24
------------;

=========================================================
Pre-Defined functions in dict
=========================================================
=>In dict object, we have the following function for performing Various Operations.

1. clear()
2. pop()
3. popitem()
4. copy()
--------------;
5. get()
6. keys()
7. values()
8. items()
9. update()
------------------------------------------------------------------------------------------------------------------------
----------
1. clear()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: dictobj.clear()
=>This Function is used for Removing all the elements of non-empty dict object
=>If we call this function upon empty dict object then we get None / No Output.
----------------
Examples
----------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,type(d1),id(d1))---{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} <class 'dict'>
2364664861568
>>> d1.clear()
>>> print(d1,type(d1),id(d1))----{} <class 'dict'> 2364664861568
>>> print(d1.clear())----------None
>>> print(dict().clear())---------None
>>> print({}.clear())--------------None
------------------------------------------------------------------------------------------------------------------------
----------
2. pop()
------------------------------------------------------------------------------------------------------------------------
----------
=>Syntax: dictobj.pop(Key)
---------------
=>This Function is used for Removing (Key,value) from non-empty dictobject by passing Value of
Key.
=>If the Value of Key does not exist then we get KeyError
=>If we call this pop(), upon empty dict object then we get KeyError.
----------------
Examples:
----------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))---------------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669155776
>>> d1.pop(20)--------------------'Java'
>>> print(d1,id(d1))--------------{10: 'Python', 30: 'C++', 40: 'C'} 2364669155776
>>> d1.pop(30)------------------'C++'
>>> d1.pop(40)0---------------'C'
>>> print(d1,id(d1))--------------{10: 'Python'} 2364669155776
>>> d1.pop(50)------------------------KeyError: 50
>>> print(d1,id(d1))--------{10: 'Python'} 2364669155776
>>> d1.pop(10)-------------'Python'
>>> print(d1,id(d1))--------{} 2364669155776
>>> d1.pop(10)-----------KeyError: 10
>>> dict().pop(10)----------------KeyError: 10
>>> {}.pop("Python")-----KeyError: 'Python'
------------------------------------------------------------------------------------------------------------------------
----------
3. popitem()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: dictobj.popitem()
------------
=>This Function is used for Removing Last (Key,value) entry from non-empty dictobject.
=>If we call this popitem(), upon empty dict object then we get KeyError.
Examples:
---------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))-------------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669156096
>>> d1.popitem()---------------(40, 'C')
>>> print(d1,id(d1))------------{10: 'Python', 20: 'Java', 30: 'C++'} 2364669156096
>>> d1.popitem()--------------(30, 'C++')
>>> print(d1,id(d1))----------{10: 'Python', 20: 'Java'} 2364669156096
>>> d1.popitem()-----------(20, 'Java')
>>> print(d1,id(d1))-------------{10: 'Python'} 2364669156096
>>> d1.popitem()-------------(10, 'Python')
>>> print(d1,id(d1))--------------{} 2364669156096
>>> d1.popitem()-----------KeyError: 'popitem(): dictionary is empty'
>>> dict().popitem()----------KeyError: 'popitem(): dictionary is empty'
>>> {}.popitem()-----------KeyError: 'popitem(): dictionary is empty'
------------------------------------------------------------------------------------------------------------------------
----------
4. copy()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: dictobj2=dictobj1.copy()
------------
=>This function is used for Copying the content of One dict object into another dict object.
------------------
Examples:
------------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))---------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669156416
>>> d2=d1.copy() # Shallow Copy
>>> print(d2,id(d2))----{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669156096
>>> d1[50]="Dsc"
>>> d2[60]="Django"
>>> print(d1,id(d1))----{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C', 50: 'Dsc'} 2364669156416
>>> print(d2,id(d2))---{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C', 60: 'Django'} 2364669156096
----------------
Deep Copy Process of dict objects
---------------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))---------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669155776
>>> d2=d1 # Deep Coy
>>> print(d2,id(d2))---------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669155776
>>> d1[50]="Dsc"
>>> print(d1,id(d1))---------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C', 50: 'Dsc'} 2364669155776
>>> print(d2,id(d2))---------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C', 50: 'Dsc'} 2364669155776
------------------------------------------------------------------------------------------------------------------------
----------
5. get()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: This Function is used for obtaining Value of Value by Passing Value of Key.
-----------
=>if the value of Key does not exist then we get None as a result
(OR)
Syntax: dictobj[Key]---->Will give Value of Value if Key Present otherwise get KeyError
----------------
Examples:
----------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))-------------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669156096
>>> v=d1.get(10)
>>> print(v)------------Python
>>> v=d1.get(20)
>>> print(v)-----------Java
#OR
>>> d1.get(10)--------'Python'
>>> d1.get(20)--------'Java'
>>> print(d1.get(200))-------None
>>> v=d1.get(200)
>>> print(v)--------------None
>>> print(dict().get(10))---------None
>>> print({}.get(10))------------None
-------------------------OR----------------------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))-----------------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669156288
>>> d1.get(10)--------------'Python'

>>> d1[10]--------------------'Python'
>>> d1[20]---------------------'Java'
>>> d1[40]--------------------'C'
>>> d1[400]-------------------KeyError: 400
>>> print(d1.get(400))--------None
------------------------------------------------------------------------------------------------------------------------
----------
6. keys()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: varname=dictobj.keys()
------------ (OR)
dictobj.keys()

=>This Function is used for obtaining set of Keys in the form of dict_keys object.
---------------
Examples:
-----------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))----------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669156096
>>> ks=d1.keys()
>>> print(ks,type(ks))---------dict_keys([10, 20, 30, 40]) <class 'dict_keys'>
>>> for k in ks:
... print(k)
...
10
20
30
40
>>> for k in d1.keys():
... print(k)
...
10
20
30
40
>>> for k in d1.keys():
... print(k,"-->",d1.get(k))
...
10 --> Python
20 --> Java
30 --> C++
40 --> C
>>> for k in d1.keys():
... print(k,"-->",d1[k])
...
10 --> Python
20 --> Java
30 --> C++
40 --> C
------------------------------------------------------------------------------------------------------------------------
----------
7. values()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: varname=dictobj.values()
------------ (OR)
dictobj.values()

=>This Function is used for obtaining set of Values in the form of dict_values object.
------------------
Examples
------------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> print(d1,id(d1))---------{10: 'Python', 20: 'Java', 30: 'C++', 40: 'C'} 2364669156288
>>> vs=d1.values()
>>> print(vs)---------dict_values(['Python', 'Java', 'C++', 'C'])
>>> for v in vs:
... print(v)
...
Python
Java
C++
C
>>> for v in d1.values():
... print(v)
...
Python
Java
C++
C
---------------------------------
MOST IMP
---------------------------------
>>> for x in d1:
... print(x)
...
10
20
30
40

>>> for x in d1:


... print(x,"-->",d1[x])
...
10 --> Python
20 --> Java
30 --> C++
40 --> C
------------------------------------------------------------------------------------------------------------------------
----------
8. items()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: varname=d1.items()
------------
This Function is used for obtaining (Key,value) in the form of tuples of list in the object of
dict_items.
------------------
Examples:
-----------------
>>> d1={10:"Python",20:"Java",30:"C++",40:"C"}
>>> kvs=d1.items()
>>> print(kvs)-------dict_items([(10, 'Python'), (20, 'Java'), (30, 'C++'), (40, 'C')])
>>> for kv in kvs:
... print(kv)
...
(10, 'Python')
(20, 'Java')
(30, 'C++')
(40, 'C')
>>> for kv in d1.items():
... print(kv)
...
(10, 'Python')
(20, 'Java')
(30, 'C++')
(40, 'C')
>>> for k,v in d1.items():
... print(k,"--->",v)
...
10 ---> Python
20 ---> Java
30 ---> C++
40 ---> C
------------------------------------------------------------------------------------------------------------------------
----------
9. update()
------------------------------------------------------------------------------------------------------------------------
----------
Syntax: dictobj1.update(dictobj2)

=>This Function isd used for Joining / Updating / Modifying the dictobj1 content with DictObj2
content.
------------------
Exmaples:
------------------
>>> d1={10:1.2,20:3.4,30:4.5}
>>> d2={100:"Apple",200:"Kiwi"}
>>> print(d1,type(d1))------------{10: 1.2, 20: 3.4, 30: 4.5} <class 'dict'>
>>> print(d2,type(d2))--------------{100: 'Apple', 200: 'Kiwi'} <class 'dict'>
>>> d1.update(d2)
>>> print(d1,type(d1))---------{10: 1.2, 20: 3.4, 30: 4.5, 100: 'Apple', 200: 'Kiwi'} <class 'dict'>
>>> print(d2,type(d2))------------{100: 'Apple', 200: 'Kiwi'} <class 'dict'>
---------------------------------------------------
>>> d1={10:1.2,20:3.4,30:4.5}
>>> d2={100:"Apple",20:13.4}
>>> print(d1,type(d1))-----------{10: 1.2, 20: 3.4, 30: 4.5} <class 'dict'>
>>> print(d2,type(d2))-----------{100: 'Apple', 20: 13.4} <class 'dict'>
>>> d1.update(d2)
>>> print(d1,type(d1))--------{10: 1.2, 20: 13.4, 30: 4.5, 100: 'Apple'} <class 'dict'>
>>> print(d2,type(d2))--------{100: 'Apple', 20: 13.4} <class 'dict'>
-------------------------------------------
>>> d1={10:1.2,20:3.4,30:4.5}
>>> d2={10:11.2,20:13.4,30:14.5}
>>> print(d1,type(d1))-----------{10: 1.2, 20: 3.4, 30: 4.5} <class 'dict'>
>>> print(d2,type(d2))-----------{10: 11.2, 20: 13.4, 30: 14.5} <class 'dict'>
>>> d1.update(d2)
>>> print(d1,type(d1))------------{10: 11.2, 20: 13.4, 30: 14.5} <class 'dict'>
>>> print(d2,type(d2))------------{10: 11.2, 20: 13.4, 30: 14.5} <class 'dict'>
==========================x============================================
========
Most Imp Points
-----------------------------------------------
=>Dict in Dict--->Possible to write
----------------------------------------------
>>> d1={"sno":10,"sname":"Rossum","imarks":{"cm":17,"cppm":16,"pym":18},"emarks":
{"cm":67,"cppm":78,"pym":70},"cname":"OUCET"}
>>> print(d1,type(d1))
{'sno': 10, 'sname': 'Rossum', 'imarks': {'cm': 17, 'cppm': 16,
'pym': 18}, 'emarks': {'cm': 67, 'cppm': 78, 'pym': 70}, 'cname': 'OUCET'} <class 'dict'>
>>> for k in d1.keys():
... print(k)
...
sno
sname
imarks
emarks
cname
>>> for v in d1.values():
... print(v)
...
10
Rossum
{'cm': 17, 'cppm': 16, 'pym': 18}
{'cm': 67, 'cppm': 78, 'pym': 70}
OUCET
>>> for v in d1.values():
... print(v,type(v))
...
10 <class 'int'>
Rossum <class 'str'>
{'cm': 17, 'cppm': 16, 'pym': 18} <class 'dict'>
{'cm': 67, 'cppm': 78, 'pym': 70} <class 'dict'>
OUCET <class 'str'>
>>> for kv in d1.items():
... print(kv)
...
('sno', 10)
('sname', 'Rossum')
('imarks', {'cm': 17, 'cppm': 16, 'pym': 18})
('emarks', {'cm': 67, 'cppm': 78, 'pym': 70})
('cname', 'OUCET')
>>> for k in d1.keys():
... print(k)
...
sno
sname
imarks
emarks
cname
>>> for k in d1.keys():
... print(k,"--->",d1.get(k))
...
sno ---> 10
sname ---> Rossum
imarks ---> {'cm': 17, 'cppm': 16, 'pym': 18}
emarks ---> {'cm': 67, 'cppm': 78, 'pym': 70}
cname ---> OUCET
>>> for v in d1.get("imarks"):
... print(v)
...
cm
cppm
pym
>>> for v in d1.get("imarks"):
... print(v,"-->",d1.get("imarks").get(v))
...
cm --> 17
cppm --> 16
pym --> 18
>>> for v in d1.get("imarks"):
... print(v,"-->",d1["imarks"][v])
...
cm --> 17
cppm --> 16
pym --> 18
=======================================================================
==
In side of dict, we define list,tuple and set also
----------------
Examples:
---------------
>>> d1={"sno":10,"sname":"Rossum","imarks":[16,18,17],"emarks":(60,77,67),"crs":
{"B.Tech(cse)", "M.Tech(AI)"}, "cname":"OUECT"}
>>> for k,v in d1.items():
... print(k,"-->",v,"--->",type(v))
...
sno --> 10 ---> <class 'int'>
sname --> Rossum ---> <class 'str'>
imarks --> [16, 18, 17] ---> <class 'list'>
emarks --> (60, 77, 67) ---> <class 'tuple'>
crs --> {'B.Tech(cse)', 'M.Tech(AI)'} ---> <class 'set'>
cname --> OUECT ---> <class 'str'>
=======================================================================
==
dict in list is Possible
----------------------------------
Examples
-----------------
>>> l1=[10,"Rossum",{"cm":16,"cppm":17,"pym":18},"OUCET"]
>>> print(l1,type(l1))---[10, 'Rossum', {'cm': 16, 'cppm': 17, 'pym': 18}, 'OUCET'] <class 'list'>
>>> for val in l1:
... print(val,type(val))
...
10 <class 'int'>
Rossum <class 'str'>
{'cm': 16, 'cppm': 17, 'pym': 18} <class 'dict'>
OUCET <class 'str'>
>>> for k,v in l1[2].items():
... print(k,"--->",v)
...
cm ---> 16
cppm ---> 17
pym ---> 18
------------------------------------------------------------------
dict in tuple is Possible
------------------------------------------------------------------
Examples:
---------------------------------------------
>>> t1=(10,"Rossum",{"cm":16,"cppm":17,"pym":18},"OUCET")
>>> print(t1,type(t1))----------(10, 'Rossum', {'cm': 16, 'cppm': 17, 'pym': 18}, 'OUCET') <class
'tuple'>
>>> for val in t1:
... print(val,type(val))
...
10 <class 'int'>
Rossum <class 'str'>
{'cm': 16, 'cppm': 17, 'pym': 18} <class 'dict'>
OUCET <class 'str'>
>>> for k,v in t1[-2].items():
... print(k,"-->",v)
...
cm --> 16
cppm --> 17
pym --> 18
--------------------------------------------------------------------------------------
dict in set not possible
--------------------------------------------------------------------------------------
>>> s1={10,"Rossum",{"cm":16,"cppm":17,"pym":18},"OUCET"}--TypeError: unhashable type:
'dict'
------------------------------------------------------------------------------------------------------------------------
-----------------

=======================================
NoneType data type
=======================================
=>'NoneType' is one the pre-defined class and treated as None type Data type
=> "None" is keyword acts as value for <class,'NoneType'>
=>The value of 'None' is not False, Space , empty , 0
=>An object of NoneType class can't be created explicitly.
--------------------------------------------------------------------
Examples:
------------------
>>> a=None
>>> print(a,type(a))------------None <class 'NoneType'>
>>> a=NoneType()---------NameError: name 'NoneType' is not defined
>>> l1=[]
>>> print(l1.clear())------------None
>>> s1=set()
>>> print(s1.clear())---------None
>>> d1=dict()
>>> print(d1.clear())-----------None
>>> d1={10:1.2,20:3.4}
>>> print(d1.get(100))---------None
-------------------------------------------------------------------------------------------------------------------

Day – 25

========================================================
Number of approaches for developing Python Programs

========================================================
---------------------------
=>Def. of Program:
---------------------------
=>Set of Optimized Instructions is Called Program.
=>Optimized Instructions are nothing but they takes Less Memory Space and Less Execution Time.
=>The Purpose of Writing Programs in any Language is that " To Solve Real Time Problems".
-----------------------------
=>In Python Programming, we have Two Approaches to write the Programs. They are
1. By using Interactive Approach
2. By using Batch Mode Approach
------------------------------------------------------------------------------------------------------------------------
--------
1. By using Interactive Approach
------------------------------------------------------------------------------------------------------------------------
--------
=>Interactive Approach, Python Programmer can Issue / Write Single Instruction at a time and gets
the
result Immediately.
=>Interactive Approach is recommended to test One Instruction at a Time But Not suitable for Big
Problem Solving approaches.
=>To Develop Big Problem Solving approaches, we must use Batch Mode Approach
------------------------------
Examples Softwares:
------------------------------
1) Python Command Prompt
2) Python IDLE Shell

=>The above Two Softwares Comes along with Python Software Installation
------------------------------------------------------------------------------------------------------------------------
--------
2. By using Batch Mode Approach
------------------------------------------------------------------------------------------------------------------------
--------
=>In Batch Mode Approach, we Define / Write set of Optmized Instructions in an Editor and we
must save on some File name with extension .py (FileName.py) and It is called Program.
=>Batch Mode Approach is always Useful for Developing Big Problem Solving approaches.
---------------------------------
Examples Softwares
---------------------------------
1) Python IDLE Shell---->ThisSoftwares Comes along with Python Software
Installation
=>In Real Time we may not Use PYTHON IDLE SHELL bcoz It may be poor in Providing in-
buitlt facilities
to the Python Programmer and Hence Industry is recommeded to use Third Party IDES
=>Some of the Third Party IDEs are
1) PyCharm
2) Ankonda Jupiter Note Book
3) VS Code
4) Spider
5) Sublime Text
6) Atom
7) Google Calb
8) Eclipse...etc

Day – 26

D=======================================================
Displaying the Result of Python Program on the Console
=======================================================
=>To Display the Result of Python Program on the Console, we use a pre-defined Function called
print().
=>In Otherwords, print() is used for Display the Result of Python Program on the Console.
=>we can print() with the following Syntaxes
=======================================================================
=========
Syntax-1 : print(Variable)
OR
print(Var1,Var2,....Var-n)
=======================================================================
=========
=>This Syntax generates either Single Variable Val or Multiple variable values.
---------------------
=>Examples:
---------------------
>>> a=10
>>> print(a)------10
>>> b=20
>>> print(b)------20
>>> c=a+b
>>> print(a,b,c)-----10 20 30
=======================================================================
=========
Syntax-2: print(Message)
(OR)
print(msg1,msg2,...msg-n)
=======================================================================
=========
=>Here Mssage, msg1,msg2....msg-n are called str type
=>This Syntax display the Message(s)
----------------------
Examples
----------------------
>>> print("hello Python world")----------hello Python world
>>> print('hello Python world')-----------hello Python world
>>> print('''hello Python world''')-------hello Python world
>>> print("""hello Python world""")-----hello Python world
>>> print("Hello","Python","World")-------Hello Python World
>>> print("Hello" + "Python" + "World")---HelloPythonWorld
>>> print("Hello"+" "+"Python"+" "+"World")---Hello Python World
NOTE: Here + operator is used for concatination of str values
>>> print("Python"+3.11)---TypeError: can only concatenate str (not "float") to str
>>> print("Python"+str(3.11))---------Python3.11
=======================================================================
=========
Syntax-3: print(Messages Cum Values)
(OR)
print(Values cum Messages)
=======================================================================
=========
=>This Syntax displays Values Cum Messages OR Messages Cum Values.
-----------------
Examples:
-----------------
>>> a=10
>>> print("Val of a="+a)--------TypeError: can only concatenate str (not "int") to str
>>> print("Val of a="+str(a))-----Val of a=10
OR
>>> print("Val of a=",a)-----------Val of a= 10
OR
>>> a=10
>>> print(a,"is the value of a")-------10 is the value of a
>>> print(str(a)+" is the value of a")--10 is the value of a
---------------------------
>>> a=10
>>> b=20
>>> c=a+b
>>> print("sum=",c)-----------sum= 30
>>> print(c,"is the sum")-------30 is the sum
>>> print("sum of",a,"and",b,"=",c)-------sum of 10 and 20 = 30
-----------------------------------------------------------------------------------
>>> a=10
>>> b=20
>>> c=30
>>> d=a+b+c
>>> print("Sum of",a,",",b,"and",c,"=",d)---------Sum of 10 , 20 and 30 = 60
=======================================================================
=========
Syntax-4: print(Messages Cum Values with format() )
(OR)
print(Values cum Messages with format() )
=======================================================================
=========
=>This Syntax displays Values Cum Messages OR Messages Cum Values with format()
-------------------------
Examples
-------------------------
>>> a=10
>>> print("Val of a={}".format(a) )--------Val of a=10
>>> print("{} is the value of a".format(a))----10 is the value of a
-------------------
>>> sno=10
>>> name="Ram"
>>> print("My Number is {} and name is {}".format(sno,name))--My Number is 10 and name is
Ram
-----------------------
>>> a=10
>>> b=20
>>> c=a+b
>>> print("Sum of {} and {}={}".format(a,b,c))---Sum of 10 and 20=30
>>> print("sum({},{})={}".format(a,b,c))---sum(10,20)=30
=======================================================================
=========
Syntax-5: print(Messages Cum Values with format specifier )
(OR)
print(Values cum Messages with format specifier )
=======================================================================
=========
=>This Syntax displays Values Cum Messages OR Messages Cum Values with format Specifiers
=>In Python Programming, we Use %d for displying Integer data, %f for displying float data and
%s for
displaying str data.
=>In Any Value does not contain any format specifier and if we want to dispay such type of Values
then
we must convert them into str by using str() and use %s.
---------------------------------
Examples
---------------------------------
>>> sno=10
>>> sname="Ram"
>>> marks=44.56
>>> print("My Number is %d and name is %s and marks is %f" %(sno,sname,marks))
My Number is 10 and name is Ram and marks is 44.560000
>>> print("My Number is %d and name is %s and marks is %0.2f" %(sno,sname,marks))
My Number is 10 and name is Ram and marks is 44.56
>>> print("My Number is %d and name is %s and marks is %0.3f" %(sno,sname,marks))
My Number is 10 and name is Ram and marks is 44.560
------------------------------------------------
>>> a=10
>>> b=20
>>> c=a+b
>>> print("sum of %d and %d=%d" %(a,b,c))---sum of 10 and 20=30
>>> print("sum of %f and %f=%f" %(a,b,c))-----sum of 10.000000 and 20.000000=30.000000
>>> print("sum of %0.2f and %0.2f=%0.3f" %(a,b,c))--sum of 10.00 and 20.00=30.000
-----------------------------
>>> lst=[100,"Ram",45.67,"Python",True]
>>> print("Content of list=",lst)----------Content of list= [100, 'Ram', 45.67, 'Python', True]
>>> print("Content of list={}".format(lst))-----Content of list=[100, 'Ram', 45.67, 'Python', True]
>>> print("Content of list=%d" %lst)---TypeError: %d format: a real number is required, not list
>>> print("Content of list=%s" %str(lst))---Content of list=[100, 'Ram', 45.67, 'Python', True]
----------------------------------------
>>> d1={10:"Dinesh",20:"Ram",30:"Naresh"}
>>> print("Content of dict=%s" %str(d1))-----Content of dict={10: 'Dinesh', 20: 'Ram', 30:
'Naresh'}
=======================================================================
=========
Syntax-6: print(Value, end=" ")
=======================================================================
=========
=>This Syntax displays the values on the console in same Line.
-----------------
Examples:
-----------------
>>> r=range(10,101,20)
>>> for val in r:
... print(val)
...
10
30
50
70
90
>>> for val in r:
... print(val,end=" ")---- 10 30 50 70 90
--------------
>>> for val in r:
... print(val,end="->")-------- 10->30->50->70->90
=============================x===============================
Most Imp
=============================================================
>>> s="PYTHON"
>>> print(s)------------PYTHON
>>> s=s+s+s
>>> print(s)------------PYTHONPYTHONPYTHON
-----------------------
>>> s="PYTHON"
>>> print(s)-----------PYTHON
>>> s=s*3 # Here * is called Repetation Operator
>>> print(s)----------PYTHONPYTHONPYTHON
>>> print(2*3) # Here * is called Mul Operator
6
>>> print("KVR"*5)------------KVRKVRKVRKVRKVR
>>> print("22"*4)-------------22222222
>>> print("22"*"4")--------------TypeError: can't multiply sequence by non-int of type 'str'
----------------------------------
>>> print("=")------ =
>>> print("="*25) # ==========================================
=======================================================================
=

--------------------------------------------

You might also like