SlideShare a Scribd company logo
1 of 17
Informatics Practices code (065)
Topic – Tuple
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Tuple in Python
 Tuple is an ordered sequence of items
same as list. The only difference is that
tuple are immutable.
 Tuples once created cannot be modified It
is defined within parentheses () where
items are separated by commas
 The values of tuple is either string or
numeric.
 For example:(“t”, ”u”, ”p”, ”l”, ”e”) #String
(1,2,3,4) #Numeric
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Creating a Tuple
Creating w tuple with parentheses.
A tuple is created by placing all the items
(elements) inside parentheses ().
Example :
>>> T = ('p','y','t','h','o','n')
>>> type(T)
<class 'tuple'>
Creating tuple without parentheses.
A tuple can also be created without using parentheses.
This is known as tuple packing.
Example: >>> my_T = 1,2,3,
>>> type(T)
<class 'tuple'>
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Access Tuple Elements
 There are various ways in which we can
access the elements of a tuple.
 Indexing:
Indexing is way to access the element of
tuple.
Indexing are two types:-
 Positive Indexing
We can use the index operator [] to access
an item in a tuple where the index starts
from 0.
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Cont….
Negative Indexing:
 Python also allows negative indexing for
accessing elements of tuple.
 The index of -1 refers to the last item, -2
to the second last item and so on.
Indexing of Tuple -
-6 -5 -4 -3 -2 -1
0 1 2 3 4 5
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
P Y T H O N
Program to access tuple
element by indexing
>>> my_tuple = ('p','y','t','h','o','n')
>>> print(my_tuple[-3])
h
>>> print(my_tuple[-5])
y
>>> print(my_tuple[2])
t
>>> print(my_tuple[4])
o
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Slicing:
 We can access a range of items in a tuple by using
the slicing operator – colon”:”.
Syntax of slicing:
T (start : stop : step)
Slicing creates list of elements falling between indexes
start & stop , not including stop (upto indexing before
stop).
Slicing include positive & negative indexing-
-7 -6 -5 -4 -3 -2 -1
0 1 2 3 4 5 6
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
P A T I D A R
Program related to
slicing:
my_tuple = ("Gori","Radhika","Raj","Pari")
>>> my_tuple[1:3]
('Radhika', 'Raj')
>>> my_tuple1
=(10,15,20,25,30,35,40,45,50,55,60,65)
>>> my_tuple1[3:10]
(25, 30, 35, 40, 45, 50, 55)
>>> my_tuple1[2:9:2]
(20, 30, 40, 50)
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Changing a Tuple:
Tuples are immutable that means we can not
be changed once it has been assigned.
We can change tuple element by converting
tuple into list .
We can change element of list by their
indexing .
Program to change element of tuple:
>>> my_tuple = (10,50,40,20,3,5,30,9)
>>> L = list(my_tuple)
>>> L[5] = 90
>>> my_tuple = tuple(List)
>>> print(my_tuple)
(10, 50, 40, 20, 3, 90, 30, 9)
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Use of operates in tuples:
 Addition operates: It is used to add two or
more tuples, to create new tuple.
Program to add a tuple-
>>> T1 = (12,30,50,16,15)
>>> T2 = (20,10,2,5,4,6)
>>> T3 = (3,4,6,8,7)
>>> T = T1+T2+T3
>>> print(T)
(12, 30, 50, 16, 15, 20, 10, 2, 5, 4, 6, 3, 4, 6,
8, 7)
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Cont….
Multiplication operator:
Multiplication operator to replicate a list
specified number of times .
Program to complete tuple:
>>> my_tuple = (1,2,3,4,5)
>>> my_tuple1 = my_tuple*3
>>> print(my_tuple1)
(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Cont….
Membership operators:
Membership operators are-
 in and not in.
It is used to check the element ‘in’ and ‘not in’ in tuple .
Program of relationship operators:
>>> my_tuple1 = ("Raj","Pari","Raju")
>>> "Pari"in(my_tuple1)
True
>>> "Mohit"in(my_tuple1)
False
>>> my_tuple = (10,20,30,40,50)
>>> 30in(my_tuple)
True
>>> 70in(my_tuple)
False
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
>>> my_tuple = (2,5,8,10,1)
>>> 10 not in(my_tuple)
False
>>> my_tuple = (2,5,8,10,1)
>>> 4 not in(my_tuple)
True
>>> my_tuple = ("Mohit","Rohit","Parinika")
>>> "Parinika" not in(my_tuple)
False
>>> my_tuple = ("Mohit","Rohit","Parinika")
>>> "Meet" not in(my_tuple)
True
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Cont…
Deleting a Tuple
 We cannot change the elements in a
tuple. That means , we cannot delete or
remove items from a tuple.
 But , in tuple we can delete the elements
by using the keyword del.
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Tuple Programs-
1.
>>> T = ("tuple",False,3.2,1)
>>> print(T)
('tuple', False, 3.2, 1)
2.
>>> x = ("apple","banana","cherry")
>>> y = list(x)
>>> y[1] = "kiwi"
>>> x = tuple(y)
>>> print(x)
('apple', 'kiwi', 'cherry')
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
3.
>>> tuple = ("Check")*3
>>> print(tuple)
CheckCheckCheck
4.
>>> P = (11,14,15,13,2,8,9)
>>> q = (2,5,7,9,8,3)
>>> r = ('a','e','i','o','u')
>>> H = (P+q+r)
>>> print(H)
(11, 14, 15, 13, 2, 8, 9, 2, 5, 7, 9, 8, 3, 'a', 'e', 'i', 'o',
'u')
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
Cont…
Thank You
MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL

More Related Content

What's hot

What's hot (20)

Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
LIST IN PYTHON
LIST IN PYTHONLIST IN PYTHON
LIST IN PYTHON
 
Sorting
SortingSorting
Sorting
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Python list
Python listPython list
Python list
 
Arrays searching-sorting
Arrays searching-sortingArrays searching-sorting
Arrays searching-sorting
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Python Collections
Python CollectionsPython Collections
Python Collections
 
Python Course for Beginners
Python Course for BeginnersPython Course for Beginners
Python Course for Beginners
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
pyton Notes9
pyton Notes9pyton Notes9
pyton Notes9
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
 
Python List Comprehensions
Python List ComprehensionsPython List Comprehensions
Python List Comprehensions
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
Road to Power Query NINJA – 1st STEP
Road to Power Query NINJA – 1st STEP Road to Power Query NINJA – 1st STEP
Road to Power Query NINJA – 1st STEP
 

Similar to Tuple.py

Python tuples and Dictionary
Python   tuples and DictionaryPython   tuples and Dictionary
Python tuples and DictionaryAswini Dharmaraj
 
PRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptxPRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptxrohan899711
 
Python Tuple.pdf
Python Tuple.pdfPython Tuple.pdf
Python Tuple.pdfT PRIYA
 
Effective tuples in phyton template.pptx
Effective tuples in phyton template.pptxEffective tuples in phyton template.pptx
Effective tuples in phyton template.pptxkarthimaathavan
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Ohgyun Ahn
 
Python programming UNIT III-Part-2.0.pptx
Python programming UNIT III-Part-2.0.pptxPython programming UNIT III-Part-2.0.pptx
Python programming UNIT III-Part-2.0.pptxPonnusamy S Pichaimuthu
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfomprakashmeena48
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesIHTMINSTITUTE
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesIHTMINSTITUTE
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxMihirDatir
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeRamanamurthy Banda
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeRamanamurthy Banda
 
Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & listsMarc Gouw
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxGaneshRaghu4
 

Similar to Tuple.py (20)

Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
 
Python tuples and Dictionary
Python   tuples and DictionaryPython   tuples and Dictionary
Python tuples and Dictionary
 
PRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptxPRESENTATION ON TUPLES.pptx
PRESENTATION ON TUPLES.pptx
 
Python Tuple.pdf
Python Tuple.pdfPython Tuple.pdf
Python Tuple.pdf
 
Effective tuples in phyton template.pptx
Effective tuples in phyton template.pptxEffective tuples in phyton template.pptx
Effective tuples in phyton template.pptx
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Python programming UNIT III-Part-2.0.pptx
Python programming UNIT III-Part-2.0.pptxPython programming UNIT III-Part-2.0.pptx
Python programming UNIT III-Part-2.0.pptx
 
Slicing in Python - What is It?
Slicing in Python - What is It?Slicing in Python - What is It?
Slicing in Python - What is It?
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
 
updated_tuple_in_python.pdf
updated_tuple_in_python.pdfupdated_tuple_in_python.pdf
updated_tuple_in_python.pdf
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
 
Python PCEP Tuples and Dictionaries
Python PCEP Tuples and DictionariesPython PCEP Tuples and Dictionaries
Python PCEP Tuples and Dictionaries
 
Pythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptxPythonlearn-08-Lists.pptx
Pythonlearn-08-Lists.pptx
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
 
Class 5: If, while & lists
Class 5: If, while & listsClass 5: If, while & lists
Class 5: If, while & lists
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptx
 

More from nuripatidar

More from nuripatidar (9)

Python program
Python programPython program
Python program
 
Python operators
Python operatorsPython operators
Python operators
 
Python lists
Python listsPython lists
Python lists
 
Indian history
Indian historyIndian history
Indian history
 
Python basic Program
Python basic ProgramPython basic Program
Python basic Program
 
Python Programme list
Python Programme listPython Programme list
Python Programme list
 
Chemistry
ChemistryChemistry
Chemistry
 
Python statements
Python statementsPython statements
Python statements
 
Python data type
Python data typePython data type
Python data type
 

Recently uploaded

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
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
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
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 

Recently uploaded (20)

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
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
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
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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
 

Tuple.py

  • 1. Informatics Practices code (065) Topic – Tuple MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 2. Tuple in Python  Tuple is an ordered sequence of items same as list. The only difference is that tuple are immutable.  Tuples once created cannot be modified It is defined within parentheses () where items are separated by commas  The values of tuple is either string or numeric.  For example:(“t”, ”u”, ”p”, ”l”, ”e”) #String (1,2,3,4) #Numeric MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 3. Creating a Tuple Creating w tuple with parentheses. A tuple is created by placing all the items (elements) inside parentheses (). Example : >>> T = ('p','y','t','h','o','n') >>> type(T) <class 'tuple'> Creating tuple without parentheses. A tuple can also be created without using parentheses. This is known as tuple packing. Example: >>> my_T = 1,2,3, >>> type(T) <class 'tuple'> MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 4. Access Tuple Elements  There are various ways in which we can access the elements of a tuple.  Indexing: Indexing is way to access the element of tuple. Indexing are two types:-  Positive Indexing We can use the index operator [] to access an item in a tuple where the index starts from 0. MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 5. Cont…. Negative Indexing:  Python also allows negative indexing for accessing elements of tuple.  The index of -1 refers to the last item, -2 to the second last item and so on. Indexing of Tuple - -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL P Y T H O N
  • 6. Program to access tuple element by indexing >>> my_tuple = ('p','y','t','h','o','n') >>> print(my_tuple[-3]) h >>> print(my_tuple[-5]) y >>> print(my_tuple[2]) t >>> print(my_tuple[4]) o MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 7. Slicing:  We can access a range of items in a tuple by using the slicing operator – colon”:”. Syntax of slicing: T (start : stop : step) Slicing creates list of elements falling between indexes start & stop , not including stop (upto indexing before stop). Slicing include positive & negative indexing- -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL P A T I D A R
  • 8. Program related to slicing: my_tuple = ("Gori","Radhika","Raj","Pari") >>> my_tuple[1:3] ('Radhika', 'Raj') >>> my_tuple1 =(10,15,20,25,30,35,40,45,50,55,60,65) >>> my_tuple1[3:10] (25, 30, 35, 40, 45, 50, 55) >>> my_tuple1[2:9:2] (20, 30, 40, 50) MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 9. Changing a Tuple: Tuples are immutable that means we can not be changed once it has been assigned. We can change tuple element by converting tuple into list . We can change element of list by their indexing . Program to change element of tuple: >>> my_tuple = (10,50,40,20,3,5,30,9) >>> L = list(my_tuple) >>> L[5] = 90 >>> my_tuple = tuple(List) >>> print(my_tuple) (10, 50, 40, 20, 3, 90, 30, 9) MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 10. Use of operates in tuples:  Addition operates: It is used to add two or more tuples, to create new tuple. Program to add a tuple- >>> T1 = (12,30,50,16,15) >>> T2 = (20,10,2,5,4,6) >>> T3 = (3,4,6,8,7) >>> T = T1+T2+T3 >>> print(T) (12, 30, 50, 16, 15, 20, 10, 2, 5, 4, 6, 3, 4, 6, 8, 7) MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 11. Cont…. Multiplication operator: Multiplication operator to replicate a list specified number of times . Program to complete tuple: >>> my_tuple = (1,2,3,4,5) >>> my_tuple1 = my_tuple*3 >>> print(my_tuple1) (1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5) MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 12. Cont…. Membership operators: Membership operators are-  in and not in. It is used to check the element ‘in’ and ‘not in’ in tuple . Program of relationship operators: >>> my_tuple1 = ("Raj","Pari","Raju") >>> "Pari"in(my_tuple1) True >>> "Mohit"in(my_tuple1) False >>> my_tuple = (10,20,30,40,50) >>> 30in(my_tuple) True >>> 70in(my_tuple) False MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 13. >>> my_tuple = (2,5,8,10,1) >>> 10 not in(my_tuple) False >>> my_tuple = (2,5,8,10,1) >>> 4 not in(my_tuple) True >>> my_tuple = ("Mohit","Rohit","Parinika") >>> "Parinika" not in(my_tuple) False >>> my_tuple = ("Mohit","Rohit","Parinika") >>> "Meet" not in(my_tuple) True MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL Cont…
  • 14. Deleting a Tuple  We cannot change the elements in a tuple. That means , we cannot delete or remove items from a tuple.  But , in tuple we can delete the elements by using the keyword del. MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 15. Tuple Programs- 1. >>> T = ("tuple",False,3.2,1) >>> print(T) ('tuple', False, 3.2, 1) 2. >>> x = ("apple","banana","cherry") >>> y = list(x) >>> y[1] = "kiwi" >>> x = tuple(y) >>> print(x) ('apple', 'kiwi', 'cherry') MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL
  • 16. 3. >>> tuple = ("Check")*3 >>> print(tuple) CheckCheckCheck 4. >>> P = (11,14,15,13,2,8,9) >>> q = (2,5,7,9,8,3) >>> r = ('a','e','i','o','u') >>> H = (P+q+r) >>> print(H) (11, 14, 15, 13, 2, 8, 9, 2, 5, 7, 9, 8, 3, 'a', 'e', 'i', 'o', 'u') MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL Cont…
  • 17. Thank You MAA UMIYA PATIDAR GIRLS' HR. SEC. SCHOOL