0% found this document useful (0 votes)
5 views99 pages

Data Types in Python

The document outlines the various data types available in Python, categorized into Fundamental, Sequence, List, Set, Dict, and NoneType. It details the properties and examples of each data type, including int, float, bool, complex, and str, along with their usage and memory allocation. Additionally, it explains number systems and base conversion functions in Python.

Uploaded by

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

Data Types in Python

The document outlines the various data types available in Python, categorized into Fundamental, Sequence, List, Set, Dict, and NoneType. It details the properties and examples of each data type, including int, float, bool, complex, and str, along with their usage and memory allocation. Additionally, it explains number systems and base conversion functions in Python.

Uploaded by

benditarun20045
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

=================================================

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

===========================================
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'
---------------------------------------------------------------------------------------------
----------------------------
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==================
=======================
==============================================
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: [Link]------>Gives Real Part of Complex object


[Link]----->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([Link])---------------------- 10.0
>>> print([Link])-------------------- 3.0
>>> b=2.5+4.6j
>>> print(b,type(b))--------------- (2.5+4.6j) <class 'complex'>
>>> print([Link])------------------- 2.5
>>> print([Link])------------------ 4.6
----------------------------------------------------------------------------------------
>>> a=-3.5j
>>> print(a,type(a))------------------- (-0-3.5j) <class 'complex'>
>>> print([Link])----------------------- -0.0
>>> a=2.5j
>>> print(a,type(a))------------------- 2.5j <class 'complex'>
>>> print([Link])------------------------ 0.0
>>> print([Link])---------------------- 2.5
>>> a=-1+4.5j
>>> print(a,type(a))----------------- (-1+4.5j) <class 'complex'>
>>> print([Link])--------------------- -1.0
>>> print([Link])--------------------- 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======================
=================

2) sequential data types :\

=================================================

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======================================\

====================================================

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

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

102

>>> for val in ba[::-1]:

... print(val)

...

102

255

100

56

34
10

>>> for val in ba:

... print(val)

...

10

34

56

100

255

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

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

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

102

>>> x[1]----------------------34

>>> x[1]=234

>>> for v in x:

... print(v)

...

123

234

56

100

255

102

>>> print(x,type(x),id(x))-----bytearray(b'{\xea8d\xff\x00f') <class 'bytearray'> 2149788291888

==============================================

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)

...

>>> for val in range(6):

... print(val)
...

>>> for val in range(10):

... print(val)

...

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

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)

...

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

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

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

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

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

3
4

>>> for val in range(-5,6):

... print(val)

...

-5

-4

-3

-2

-1

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

>>> 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

==============================================================
==============================================

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

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

[Link]

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

=>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

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

Set cat : ==============================================

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

==============================================================================
==

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: [Link](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

>>> [Link]("PYTHON")

>>> print(lst,id(lst))----[10, 'Rossum', 34.56, 'PYTHON'] 2705927639808

>>> [Link](True)

>>> [Link](1+2.5j)
>>> print(lst,id(lst))----[10, 'Rossum', 34.56, 'PYTHON', True, (1+2.5j)] 2705927639808

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

2. insert()

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

Syntax: [Link](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

>>> [Link](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

>>> [Link](2,True)

>>> print(lst,id(lst))-----[10, 'Rossum', True, 'PYTHON', 44.56] 2705923376704

>>> [Link](-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

>>> [Link](10,"PYTHON")
>>> print(lst,id(lst))-----------[10, 'Rossum', 34.56, 'PYTHON'] 2705927639296

>>> [Link](-10,"HYD")

>>> print(lst,id(lst))----------['HYD', 10, 'Rossum', 34.56, 'PYTHON'] 2705927639296

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

3. clear()

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

Syntax: [Link]()

=>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

>>> [Link]()

>>> print(lst,id(lst),len(lst))------------ [] 2705927639808 0

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

>>> [Link]() -------------- No Ouput

(OR)

>>> print([Link]())----------None

>>> [].clear()-------------------No Output

(OR)

>>> print([].clear())

None

>>> print(list().clear())----------None

-------------------------------------------------------------------------------------------------------------------------
4. remove()----Based on Value

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

=>Syntax: [Link](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

>>> [Link]("Rossum")

>>> print(lst,len(lst))------------------[10, 34.56, 'Python'] 3

>>> [Link](34.56)

>>> print(lst,len(lst))--------------------[10, 'Python'] 2

>>> [Link]("Python")

>>> print(lst,len(lst))------------------[10] 1

>>> [Link](10)

>>> print(lst,len(lst))------------------[] 0

>>> [Link]("Python")--------------ValueError: [Link](x): x not in list

>>> list().remove(100)-------------------ValueError: [Link](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

>>> [Link](10)

>>> print(lst1,len(lst1))--------------[20, 30, 10, 30, 'Python', True] 6


>>> [Link](10)

>>> print(lst1,len(lst1))--------------[20, 30, 30, 'Python', True] 5

>>> [Link](30)

>>> print(lst1,len(lst1))--------------[20, 30, 'Python', True] 4

>>> [Link](30)

>>> print(lst1,len(lst1))--------------[20, 'Python', True] 3

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

5. pop(index)----Index Based

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

=>Syntax: [Link](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]

>>> [Link](3)-------------------------10

>>> print(lst1)--------------------------[10, 20, 30, 30, 'Python', True]

>>> [Link](-4)-----------------------30

>>> print(lst1)--------------------------[10, 20, 30, 'Python', True]

>>> [Link](0)------------------------10

>>> print(lst1)--------------------------[20, 30, 'Python', True]

>>> [Link](0)------------------------20

>>> print(lst1)------------------------[30, 'Python', True]


>>> [Link](0)----------------------30

>>> print(lst1)-------------------------['Python', True]

>>> [Link](0)-----------------------'Python'

>>> print(lst1)------------------------[True]

>>> [Link](0)-----------------------True

>>> print(lst1)-------------------------[]

>>> [Link](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: [Link]()

=>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']

>>> [Link]()--------------------------'Python'

>>> print(lst)---------------------------[10, 'Rossum', 34.56]

>>> [Link]()-------------------------34.56

>>> print(lst)-------------------------[10, 'Rossum']

>>> [Link]()--------------------------'Rossum'
>>> print(lst)-------------------------[10]

>>> [Link]()--------------------------10

>>> print(lst)-------------------------[]

>>> [Link]()--------------------------IndexError: pop from empty list

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

>>> list().pop()----------------IndexError: pop from empty list

>>> [].pop()---------------------IndexError: pop from empty list

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

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: [Link](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]

>>> [Link](10)---------0

>>> [Link](20)---------1

>>> [Link](30)----------2

>>> [Link](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=[Link]()

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

Examples:

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

>>> lst1=[10,"Rossum",34.56]

>>> print(lst1,type(lst1),id(lst1))------[10, 'Rossum', 34.56] <class 'list'> 2302481827584

>>> lst2=[Link]() # Shallow Copy

>>> print(lst2,type(lst2),id(lst2))----[10, 'Rossum', 34.56] <class 'list'> 2302481486656

>>> [Link]("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

>>> [Link]("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

>>> [Link]("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

>>> [Link]("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: [Link](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]

>>> [Link](10)-------3

>>> [Link](20)-------2

>>> [Link](30)-------1

>>> [Link](40)-------0

>>> [Link]("PYTHON" )-----0

>>> list().count(10)----------0

>>> [].count(10)-------------0

-------------------------------------------------------------------------------------------------------------------------------
------------
10. reverse()

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

Syntax: [Link]()

=>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

>>> [Link]()

>>> 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

>>> [Link]()

>>> print(lst2,id(lst2))-------[300, 200, 100, 30, 20, 10] 2302485776384

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

>>> lst2=[10,20,30,100,200,300]

>>> lst3=[Link]()

>>> 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: [Link](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"]

>>> [Link](lst2,lst3)------------TypeError: [Link]() takes exactly one argument (2 given)

#### TO Solve the above Error

>>> [Link](lst2)

>>> [Link](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: [Link]()----->Sorts the given List data in ASCending Order

Syntax2: [Link](revserse=False)----->Sorts the given List data in ASCending Order

Syntax3: [Link](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

>>> [Link]()

>>> 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

>>> [Link]()

>>> print(lst,id(lst))---------[-7, -2, 6, 10, 12, 13, 45, 56] 2302481486656

>>> [Link]()

>>> 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

>>> [Link](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

>>> [Link](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']

>>> [Link](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']

>>> [Link]()

>>> 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]

>>> [Link]()----------TypeError: '<' not supported between instances of 'str' and 'int'

==================================x==========================================

=
==================================================

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']

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

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

===============================================

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']

>>> [Link](2,[16,15,18,17])

>>> print(lst)--------------------------[100, 'Karthik', [16, 15, 18, 17], 'OUCET']

>>> [Link](-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'>

>>> [Link](2,[17,15,14,19])
>>> print(studlist,type(studlist))--[100, 'DLPrince', [17, 15, 14, 19], 'OUCET'] <class
'list'>

>>> [Link]([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'>


DICT:

=====================================================

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

=========================================================

Pre-Defined functions in dict

=========================================================

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

1. clear()

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

Syntax: [Link]()

=>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

>>> [Link]()

>>> print(d1,type(d1),id(d1))----{} <class 'dict'> 2364664861568

>>> print([Link]())----------None

>>> print(dict().clear())---------None

>>> print({}.clear())--------------None

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

2. pop()

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

=>Syntax: [Link](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

>>> [Link](20)--------------------'Java'

>>> print(d1,id(d1))--------------{10: 'Python', 30: 'C++', 40: 'C'} 2364669155776

>>> [Link](30)------------------'C++'

>>> [Link](40)0---------------'C'

>>> print(d1,id(d1))--------------{10: 'Python'} 2364669155776

>>> [Link](50)------------------------KeyError: 50

>>> print(d1,id(d1))--------{10: 'Python'} 2364669155776

>>> [Link](10)-------------'Python'

>>> print(d1,id(d1))--------{} 2364669155776

>>> [Link](10)-----------KeyError: 10

>>> dict().pop(10)----------------KeyError: 10

>>> {}.pop("Python")-----KeyError: 'Python'

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

3. popitem()

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

Syntax: [Link]()

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

=>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

>>> [Link]()---------------(40, 'C')

>>> print(d1,id(d1))------------{10: 'Python', 20: 'Java', 30: 'C++'} 2364669156096

>>> [Link]()--------------(30, 'C++')

>>> print(d1,id(d1))----------{10: 'Python', 20: 'Java'} 2364669156096

>>> [Link]()-----------(20, 'Java')

>>> print(d1,id(d1))-------------{10: 'Python'} 2364669156096

>>> [Link]()-------------(10, 'Python')

>>> print(d1,id(d1))--------------{} 2364669156096

>>> [Link]()-----------KeyError: 'popitem(): dictionary is empty'

>>> dict().popitem()----------KeyError: 'popitem(): dictionary is empty'

>>> {}.popitem()-----------KeyError: 'popitem(): dictionary is empty'

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

4. copy()

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

Syntax: dictobj2=[Link]()

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

=>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=[Link]() # 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=[Link](10)

>>> print(v)------------Python

>>> v=[Link](20)

>>> print(v)-----------Java

#OR

>>> [Link](10)--------'Python'

>>> [Link](20)--------'Java'

>>> print([Link](200))-------None

>>> v=[Link](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

>>> [Link](10)--------------'Python'

>>> d1[10]--------------------'Python'

>>> d1[20]---------------------'Java'

>>> d1[40]--------------------'C'
>>> d1[400]-------------------KeyError: 400

>>> print([Link](400))--------None

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

6. keys()

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

Syntax: varname=[Link]()

------------ (OR)

[Link]()

=>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=[Link]()

>>> 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 [Link]():


... print(k)

...

10

20

30

40

>>> for k in [Link]():

... print(k,"-->",[Link](k))

...

10 --> Python

20 --> Java

30 --> C++

40 --> C

>>> for k in [Link]():

... print(k,"-->",d1[k])

...

10 --> Python

20 --> Java

30 --> C++

40 --> C

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

7. values()

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

Syntax: varname=[Link]()

------------ (OR)
[Link]()

=>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=[Link]()

>>> print(vs)---------dict_values(['Python', 'Java', 'C++', 'C'])

>>> for v in vs:

... print(v)

...

Python

Java

C++

>>> for v in [Link]():

... print(v)

...

Python

Java

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=[Link]()

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

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=[Link]()

>>> 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 [Link]():

... print(kv)

...

(10, 'Python')

(20, 'Java')

(30, 'C++')

(40, 'C')

>>> for k,v in [Link]():

... print(k,"--->",v)

...

10 ---> Python

20 ---> Java

30 ---> C++

40 ---> C
-------------------------------------------------------------------------------------------------------------------------------
---

9. update()

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

Syntax: [Link](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'>

>>> [Link](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'>

>>> [Link](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'>

>>> [Link](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":6
7,"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 [Link]():

... print(k)

...

sno

sname

imarks

emarks
cname

>>> for v in [Link]():

... print(v)

...

10

Rossum

{'cm': 17, 'cppm': 16, 'pym': 18}

{'cm': 67, 'cppm': 78, 'pym': 70}

OUCET

>>> for v in [Link]():

... 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 [Link]():

... 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 [Link]():


... print(k)

...

sno

sname

imarks

emarks

cname

>>> for k in [Link]():

... print(k,"--->",[Link](k))

...

sno ---> 10

sname ---> Rossum

imarks ---> {'cm': 17, 'cppm': 16, 'pym': 18}

emarks ---> {'cm': 67, 'cppm': 78, 'pym': 70}

cname ---> OUCET

>>> for v in [Link]("imarks"):

... print(v)

...

cm

cppm

pym

>>> for v in [Link]("imarks"):

... print(v,"-->",[Link]("imarks").get(v))

...

cm --> 17

cppm --> 16
pym --> 18

>>> for v in [Link]("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":{"[Link](cse)
", "[Link](AI)"}, "cname":"OUECT"}

>>> for k,v in [Link]():

... 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 --> {'[Link](cse)', '[Link](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([Link]())------------None

>>> s1=set()

>>> print([Link]())---------None

>>> d1=dict()

>>> print([Link]())-----------None

>>> d1={10:1.2,20:3.4}

>>> print([Link](100))---------None

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

You might also like