SlideShare a Scribd company logo
1 of 24
Python Programming-Part8
Megha V
Research Scholar
Dept of IT
Kannur University
Tuples
• Sequence data type
• Tuples are enclosed in parentheses ()
• The values can not be updated
• Tuples can be considered as read-only lists
Tuples
• Example:
first_tuple = (‘abcd’,147,2.43,’Tom’,74.9)
small_tuple = (111,’Tom’)
print(first_tuple) #Prints complete tuple
print(first_tuple[0]) #Prints first element of the tuple
print(first_tuple[1:3]) #Prints elements starting from 2nd till 3rd
print(first_tuple[2:]) # Prints elements starting from 3rd element
print(small_tuple*2) # Prints tuples 2 times
print(first_tuple+small_tuple) # Prints concatenated tuple
Output
(‘abcd’,147,2.43,’Tom’,74.9)
abcd
(147,2.43)
(2.43,’Tom’,74.9)
(111,’Tom’,111,’Tom’)
(‘abcd’,147,2.43,’Tom’,74.9(111,’Tom’)
Deleting Tuple
• To delete an entire tuple we can use the del statement
• Example: It is not possible to remove individual items from a tuple
• It is possible to create tuples which contain mutable objects, such as lists
Example:
tuple1=([1,2,3],[‘apple’,’pear’,’orange’])
print(tuple1)
del tuple1
Output
t=([1,2,3],[‘apple’,’pear’,’orange’])
Tuples
• It is possible to pack values to a tuple and unpack values from a tuple
• We can create tuples without parenthesis
• The reverse operation is called sequence unpacking
• Sequence unpacking requires that there are as many variable on the
left side of the equal sign as there are elements in the sequence.
Tuples
Example:
t= “apple”,1,100
print(t)
x,y,z=t
print(x)
print(x)
print(x)
Output
(‘apple’,1,100)
apple
1
100
Built-in Tuple functions
1. len(tuple)- Gives the total lenghth of the tuple
tuple1=(‘abcd’,147,2.43,’Tom’)
print(len(tuple)) #4
2. max(tuple)- Returns item from the tuple with maximum value
tuple1=(1200,147,2.43,1.12)
print(“Maximum value in tuple1 is:”,max(tuple1))
Output
Maximum value in tuple1 is 1200
3. min(tuple) – Returns item from tuple with minimum value
print(“Minimum value in tuple1 is:”,min(tuple1))
Output
Minimum value in tuple1 is 1.12
Built-in Tuple functions
4. tuple(seq) – Returns a converted tuple from list
list=[‘abcd’,147,2.43,’Tom’]
print(“Tuple:”,tuple(list))
Output
Tuple:(‘abcd’,147,2.43,’Tom’)
Set
• Unordered collection of unique items
• Set is defined by values separated by comma inside braces{}
• It can have any number of items and they may be of different types
(integer, float, tuple, string etc)
• We can not change or access an item using indexing or slicing
• We can perform set operations like union, intersection, difference, on
two sets.
• Set have unique values, eliminate duplicates
• Empty set is created by the function set()
Set
Example
s1={1,2,3}
print(s1)
s2={1,2,3,2,1,2} #output will contain only unique values
print(s2)
s3={1,2.4,’apple’,’Tom’,3} #set of mixed data types
print(s3)
#s4={1,2,[3,4]} # set can not have mutable items
#print(s4) #hence not permitted
s5=set([1,2,3,4]) # using set function to create set from list
print(s5)
Output
{1,2,3}
{1,2,3}
{1,3,2.4,’apple’,’Tom’}
{1,2,3,4}
Built-in set functions
1. len(set) – Returns length or total number of items in a set
set1={‘abcd’,147,2.43,’Tom’}
print(len(set1)) #4
2. max(set) – Returns item from set with maximum value
set1={1200,1.12,300,2.43,147}
print(“Maximum value is:”,max(set1))
Output
Maximum value is:1200
3. min (set) – Returns item with minimum value
print(“Minimum value is:”,min(set1))
Output
Minimum value is:1.12
Built-in set functions
4. sum (set) – Returns the sum of all item in the set
set1={147,2.43}
print(“Sum of elements in”,set1,”is”,sum(set1))
Output
Sum of elements in {147,2.43} is 149.23
5. sorted (set) – Returns a new sorted list.
set1={213,100,289,40,23,1,1000}
set2=sorted(set1)
print(“Elements before sorting:”,set1)
print(“Elements after sorting:”,set2)
Output
Elements before sorting:{213,100,289,40,23,1,1000}
Elements after sorting:{1,23,40,100,213,289,1000}
Built-in set functions
6. enumerate(set) – Returns an enumerate object.
It contains the index and value of all the items of set as a pair
set1={213,100,289,40,23,1,1000}
print(“enumerate(set):”,enumerate(set1))
Output
enumerate(set): <enumerate object at 0x00F75728>
7. any(set) – Returns True, if the set contains at least one item. Otherwise returns False
set1=set()
set2={1,2,3,4}
print(“any (set):”,any(set1))
print(“any (set):”,any(set2))
Output
any(set): False
any(set):True
Built-in set functions
8. all(set) – Returns True, if all the elements are true or the set is empty
set1=set()
set2={1,2,3,4}
print(“all(set):”,all(set1))
print(“all(set):”,all(set2))
Output
all(set):True
all(set):True
Built-in set methods
1. set.add(obj) – Adds an element obj to a set
set1={3,8,2,6}
set1.add(9)
print(set1) # {8,9,2,3,6}
2. set.remove(obj) – Removes an element obj from set.
Raise an error if the set is empty
set1={3,8,2,6}
set1.remove(8)
print(set1) # {2,3,6}
Built-in set methods
3. set.discard(obj) – Removes an item obj from set.
Nothing happens if the element to be deleted is not
present
set1={3,8,2,6}
set1.discard(8)
set1.discard(10)
4. set.pop() – Removes an returns an arbitrary set element.
Raise Key error if set is empty
set1={3,8,2,6}
set1.pop()
print(“set after poping:”,set1) # {2,3,6}
Built-in set methods
5. set1.union(set2) – Returns the union of two sets as a new set
set1={3,8,2,6}
set2={4,2,1,9}
set3=set1.union(set2) #unique values will be taken
print(set3) # {1,2,3,4,6,8,9}
6. set1.update (set2) – Update a set with the union of itself and others. The
result will be sorted in set1
set1={3,8,2,6}
set2={4,2,1,9}
set1.update(set2)
print(set1) # {1,2,3,4,6,8,9}
Built-in set methods
7. set1.intersection(set2) – Returns the intersection of two sets as a
new set
set1={3,8,2,6}
set2={4,2,1,9}
set3=set1.intersection(set2
print(set3) # {2}
8. set1.intersection_update() – Update the set with the intersection of
itself and another.
result will be stored in set1
set1={3,8,2,6}
set2={4,2,1,9}
set1.intersection_update(set2)
print(set1) # {8,2,3,6}
Built-in set methods
9. set1.difference(set2) – Returns the difference of two or more sets into a new set
set1={3,8,2,6}
set2={4,2,1,9}
set3=set1.difference(set2)
print(set3) # {8,3,6}
10. set1.difference_update() – Removes all elements of another set set2 from set1
and the result is stored in set1
set1={3,8,2,6}
set2={4,2,1,9}
set1.difference_update(set2)
print(set1) # {8,3,6}
Built-in set methods
11. set1.symmetric_difference(set2)- Return the symmetric difference of two sets
as a new set.
set1={3,8,2,6}
set2={4,2,1,9}
set3=set1.symmetric_difference(set2)
print(set3) # {1,3,4,6,8,9}
12. set1.difference_update(set2)- Update a set with the symmetric difference of
itself and another
set1={3,8,2,6}
set2={4,2,1,9}
set1.symmetric_difference_update(set2)
print(set1) # {1,3,4,6,8,9}
Built-in set methods
13.set1.isdisjoint(set2) – Returns True if two sets have a null intersection
set1={3,8,2,6}
set2={4,7,1,9}
print(“Result of set1.isdisjoint(set2):”,set1.isdisjoint(set2))
Output
Result of set1.isdisjoint(set2): True
14. set1.issubset(set2) – Returns True if set1 is a subset of set2
set1={3,8}
set2={38,4,7,1,9}
print(“Result of set1.issubset(set2):”,set1.issubset(set2))
Output
Result of set1.issubset(set2): True
Built-in set methods
15. set1.issuperset(set2) – Returns True, if set1 is a super set of set2
set1={3,8,4,6}
set2={3,8}
print(“Result of set1.issuperset(set2):”,set1.issuperset(set2))
Output
Result of set1.issuperset(set2): True
Frozenset
• Frozenset is a new class that has the characteristics of a set
• Its elements cannot be changed once assigned
• Frozensets are immutable sets
• Frozenset are hashable and can be used as keys to a dictionary
• Frozensets are creates by the function frozenset()
• Supports methods like difference(), intersection(), isdisjoint(),
issubset(), issuperset(), symmetric_difference() and union()
• Being immutable it does not have methods like add(), remove(),
update(), difference_update(),
intersection_update(),bsymmetric_difference_update() etc.
Frozen set
Example:
set1= frozenset({3,8,4,6})
print(“Set 1:”,set1)
set2=frozenset({3,8})
print(“Set 2:”,set2)
print(“Result of set1.intersection(set2):”,set1.intersection(set2))
Output
Set1: frozenset({8,3,4,6})
Set 2:frozenset({8,3})
Result of set1.intersection(set2): frozenset({8,3})

More Related Content

What's hot (20)

An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Python list
Python listPython list
Python list
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in java
 
String in java
String in javaString in java
String in java
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Array operations
Array operationsArray operations
Array operations
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Python set
Python setPython set
Python set
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Python Modules
Python ModulesPython Modules
Python Modules
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Python array
Python arrayPython array
Python array
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 

Similar to Python programming -Tuple and Set Data type

Similar to Python programming -Tuple and Set Data type (20)

PRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptxPRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptx
 
Python data structures
Python data structuresPython data structures
Python data structures
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
Set data structure
Set data structure Set data structure
Set data structure
 
Pytho_tuples
Pytho_tuplesPytho_tuples
Pytho_tuples
 
Revision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.docRevision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.doc
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
 
Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
 
ARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptxARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptx
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
arraycreation.pptx
arraycreation.pptxarraycreation.pptx
arraycreation.pptx
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 

More from Megha V

Soft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxSoft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxMegha V
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxMegha V
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptMegha V
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expressionMegha V
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7Megha V
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Megha V
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3Megha V
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming languageMegha V
 
Python programming
Python programmingPython programming
Python programmingMegha V
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplicationMegha V
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesMegha V
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm AnalysisMegha V
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and designMegha V
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithmMegha V
 
UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data  UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data Megha V
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGLMegha V
 
Msc project_CDS Automation
Msc project_CDS AutomationMsc project_CDS Automation
Msc project_CDS AutomationMegha V
 

More from Megha V (20)

Soft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxSoft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptx
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptx
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
 
Python programming
Python programmingPython programming
Python programming
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and design
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data  UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
 
Msc project_CDS Automation
Msc project_CDS AutomationMsc project_CDS Automation
Msc project_CDS Automation
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 

Python programming -Tuple and Set Data type

  • 1. Python Programming-Part8 Megha V Research Scholar Dept of IT Kannur University
  • 2. Tuples • Sequence data type • Tuples are enclosed in parentheses () • The values can not be updated • Tuples can be considered as read-only lists
  • 3. Tuples • Example: first_tuple = (‘abcd’,147,2.43,’Tom’,74.9) small_tuple = (111,’Tom’) print(first_tuple) #Prints complete tuple print(first_tuple[0]) #Prints first element of the tuple print(first_tuple[1:3]) #Prints elements starting from 2nd till 3rd print(first_tuple[2:]) # Prints elements starting from 3rd element print(small_tuple*2) # Prints tuples 2 times print(first_tuple+small_tuple) # Prints concatenated tuple Output (‘abcd’,147,2.43,’Tom’,74.9) abcd (147,2.43) (2.43,’Tom’,74.9) (111,’Tom’,111,’Tom’) (‘abcd’,147,2.43,’Tom’,74.9(111,’Tom’)
  • 4. Deleting Tuple • To delete an entire tuple we can use the del statement • Example: It is not possible to remove individual items from a tuple • It is possible to create tuples which contain mutable objects, such as lists Example: tuple1=([1,2,3],[‘apple’,’pear’,’orange’]) print(tuple1) del tuple1 Output t=([1,2,3],[‘apple’,’pear’,’orange’])
  • 5. Tuples • It is possible to pack values to a tuple and unpack values from a tuple • We can create tuples without parenthesis • The reverse operation is called sequence unpacking • Sequence unpacking requires that there are as many variable on the left side of the equal sign as there are elements in the sequence.
  • 7. Built-in Tuple functions 1. len(tuple)- Gives the total lenghth of the tuple tuple1=(‘abcd’,147,2.43,’Tom’) print(len(tuple)) #4 2. max(tuple)- Returns item from the tuple with maximum value tuple1=(1200,147,2.43,1.12) print(“Maximum value in tuple1 is:”,max(tuple1)) Output Maximum value in tuple1 is 1200 3. min(tuple) – Returns item from tuple with minimum value print(“Minimum value in tuple1 is:”,min(tuple1)) Output Minimum value in tuple1 is 1.12
  • 8. Built-in Tuple functions 4. tuple(seq) – Returns a converted tuple from list list=[‘abcd’,147,2.43,’Tom’] print(“Tuple:”,tuple(list)) Output Tuple:(‘abcd’,147,2.43,’Tom’)
  • 9. Set • Unordered collection of unique items • Set is defined by values separated by comma inside braces{} • It can have any number of items and they may be of different types (integer, float, tuple, string etc) • We can not change or access an item using indexing or slicing • We can perform set operations like union, intersection, difference, on two sets. • Set have unique values, eliminate duplicates • Empty set is created by the function set()
  • 10. Set Example s1={1,2,3} print(s1) s2={1,2,3,2,1,2} #output will contain only unique values print(s2) s3={1,2.4,’apple’,’Tom’,3} #set of mixed data types print(s3) #s4={1,2,[3,4]} # set can not have mutable items #print(s4) #hence not permitted s5=set([1,2,3,4]) # using set function to create set from list print(s5) Output {1,2,3} {1,2,3} {1,3,2.4,’apple’,’Tom’} {1,2,3,4}
  • 11. Built-in set functions 1. len(set) – Returns length or total number of items in a set set1={‘abcd’,147,2.43,’Tom’} print(len(set1)) #4 2. max(set) – Returns item from set with maximum value set1={1200,1.12,300,2.43,147} print(“Maximum value is:”,max(set1)) Output Maximum value is:1200 3. min (set) – Returns item with minimum value print(“Minimum value is:”,min(set1)) Output Minimum value is:1.12
  • 12. Built-in set functions 4. sum (set) – Returns the sum of all item in the set set1={147,2.43} print(“Sum of elements in”,set1,”is”,sum(set1)) Output Sum of elements in {147,2.43} is 149.23 5. sorted (set) – Returns a new sorted list. set1={213,100,289,40,23,1,1000} set2=sorted(set1) print(“Elements before sorting:”,set1) print(“Elements after sorting:”,set2) Output Elements before sorting:{213,100,289,40,23,1,1000} Elements after sorting:{1,23,40,100,213,289,1000}
  • 13. Built-in set functions 6. enumerate(set) – Returns an enumerate object. It contains the index and value of all the items of set as a pair set1={213,100,289,40,23,1,1000} print(“enumerate(set):”,enumerate(set1)) Output enumerate(set): <enumerate object at 0x00F75728> 7. any(set) – Returns True, if the set contains at least one item. Otherwise returns False set1=set() set2={1,2,3,4} print(“any (set):”,any(set1)) print(“any (set):”,any(set2)) Output any(set): False any(set):True
  • 14. Built-in set functions 8. all(set) – Returns True, if all the elements are true or the set is empty set1=set() set2={1,2,3,4} print(“all(set):”,all(set1)) print(“all(set):”,all(set2)) Output all(set):True all(set):True
  • 15. Built-in set methods 1. set.add(obj) – Adds an element obj to a set set1={3,8,2,6} set1.add(9) print(set1) # {8,9,2,3,6} 2. set.remove(obj) – Removes an element obj from set. Raise an error if the set is empty set1={3,8,2,6} set1.remove(8) print(set1) # {2,3,6}
  • 16. Built-in set methods 3. set.discard(obj) – Removes an item obj from set. Nothing happens if the element to be deleted is not present set1={3,8,2,6} set1.discard(8) set1.discard(10) 4. set.pop() – Removes an returns an arbitrary set element. Raise Key error if set is empty set1={3,8,2,6} set1.pop() print(“set after poping:”,set1) # {2,3,6}
  • 17. Built-in set methods 5. set1.union(set2) – Returns the union of two sets as a new set set1={3,8,2,6} set2={4,2,1,9} set3=set1.union(set2) #unique values will be taken print(set3) # {1,2,3,4,6,8,9} 6. set1.update (set2) – Update a set with the union of itself and others. The result will be sorted in set1 set1={3,8,2,6} set2={4,2,1,9} set1.update(set2) print(set1) # {1,2,3,4,6,8,9}
  • 18. Built-in set methods 7. set1.intersection(set2) – Returns the intersection of two sets as a new set set1={3,8,2,6} set2={4,2,1,9} set3=set1.intersection(set2 print(set3) # {2} 8. set1.intersection_update() – Update the set with the intersection of itself and another. result will be stored in set1 set1={3,8,2,6} set2={4,2,1,9} set1.intersection_update(set2) print(set1) # {8,2,3,6}
  • 19. Built-in set methods 9. set1.difference(set2) – Returns the difference of two or more sets into a new set set1={3,8,2,6} set2={4,2,1,9} set3=set1.difference(set2) print(set3) # {8,3,6} 10. set1.difference_update() – Removes all elements of another set set2 from set1 and the result is stored in set1 set1={3,8,2,6} set2={4,2,1,9} set1.difference_update(set2) print(set1) # {8,3,6}
  • 20. Built-in set methods 11. set1.symmetric_difference(set2)- Return the symmetric difference of two sets as a new set. set1={3,8,2,6} set2={4,2,1,9} set3=set1.symmetric_difference(set2) print(set3) # {1,3,4,6,8,9} 12. set1.difference_update(set2)- Update a set with the symmetric difference of itself and another set1={3,8,2,6} set2={4,2,1,9} set1.symmetric_difference_update(set2) print(set1) # {1,3,4,6,8,9}
  • 21. Built-in set methods 13.set1.isdisjoint(set2) – Returns True if two sets have a null intersection set1={3,8,2,6} set2={4,7,1,9} print(“Result of set1.isdisjoint(set2):”,set1.isdisjoint(set2)) Output Result of set1.isdisjoint(set2): True 14. set1.issubset(set2) – Returns True if set1 is a subset of set2 set1={3,8} set2={38,4,7,1,9} print(“Result of set1.issubset(set2):”,set1.issubset(set2)) Output Result of set1.issubset(set2): True
  • 22. Built-in set methods 15. set1.issuperset(set2) – Returns True, if set1 is a super set of set2 set1={3,8,4,6} set2={3,8} print(“Result of set1.issuperset(set2):”,set1.issuperset(set2)) Output Result of set1.issuperset(set2): True
  • 23. Frozenset • Frozenset is a new class that has the characteristics of a set • Its elements cannot be changed once assigned • Frozensets are immutable sets • Frozenset are hashable and can be used as keys to a dictionary • Frozensets are creates by the function frozenset() • Supports methods like difference(), intersection(), isdisjoint(), issubset(), issuperset(), symmetric_difference() and union() • Being immutable it does not have methods like add(), remove(), update(), difference_update(), intersection_update(),bsymmetric_difference_update() etc.
  • 24. Frozen set Example: set1= frozenset({3,8,4,6}) print(“Set 1:”,set1) set2=frozenset({3,8}) print(“Set 2:”,set2) print(“Result of set1.intersection(set2):”,set1.intersection(set2)) Output Set1: frozenset({8,3,4,6}) Set 2:frozenset({8,3}) Result of set1.intersection(set2): frozenset({8,3})