SlideShare a Scribd company logo
Chapter 13 Tuples.pptx
Computational Thinking and Programming
XI
Computer Science
(083)
Board : CBSE
Courtesy CBSE
Chapter 13 Tuples.pptx
After studying this lesson,
students will be able to:
Understand the need of Tuples;
Solve problems by using Tuples;
 Get clear idea about Tuple functions;
and
Understand the difference between
list, dictionary and tuples.
LEARNING OUTCOMES
WHAT IS TUPLE?
A tuple is a sequence of values,
which can be of any type and they are
indexed by integer. Tuples are just like list,
but we can’t change values of tuples in
place. Thus tuples are immutable.
The index value of tuple starts from 0.
A tuple consists of a number of values
separated by commas. For example:
>>> T=10, 20, 30, 40
>>> print (T)
(10, 20, 30, 40)
WHAT IS TUPLE?
CREATING EMPTY
TUPLE
CREATING EMPTY
TUPLE
ACCESSING TUPLE
ACCESSING TUPLE
ACCESSING TUPLE USING
LOOPS
ACCESSING TUPLE USING
LOOPS
ACCESSING TUPLE USING
LOOPS
OUTPUT
CHECK IF ITEM EXISTS
CHECK IF ITEM EXISTS
OUTPUT
TUPLE LENGTH
TUPLE LENGTH
OUTPUT
REMOVING A TUPLE
REMOVING A TUPLE
You cannot remove or delete or
update items in a tuple.
Tuples are unchangeable, so you
cannot remove items from it, but you can
delete the tuple completely:
NOTE: TUPLES ARE
IMMUTABLE
TUPLE METHODS
TUPLE METHODS
Python provides two built-in
methods that you can use on tuples.
1. count() Method
2. index() Method
TUPLE METHODS
1. count() Method
Return the number of times the value
appears in the tuple Count()
method
returns
total no
times
‘banana’
present in
the given
tuple
TUPLE METHODS
2. index() Method
index() Method returns index
of “banana” i.e 1
index()
Method
DIFFERENCE BETWEEN
LIST AND TUPLE
DIFFERENCE BETWEEN LIST AND TUPLE
LIST TUPLE
Syntax for list is
slightly different
comparing with tuple
Syntax for tuple is
slightly different
comparing with lists
Weekdays=[‘Sun’,’Mo
n’, ‘wed’,46,67]
type(Weekdays)
class<‘lists’>
twdays = (‘Sun’, ‘mon',
‘tue', 634)
type(twdays)
class<‘tuple’>
List uses [ and ]
(square brackets) to
bind the elements.
Tuple uses rounded
brackets( and ) to bind
the elements.
DIFFERENCE BETWEEN LIST AND TUPLE
LIST TUPLE
List can be edited once
it is created in python.
Lists are mutable data
structure.
A tuple is a list which one
cannot edit once it is
created in Python code.
The tuple is an
immutable data structure
More methods or
functions are
associated with lists.
Compare to lists tuples
have Less methods or
functions.
DIFFERENCE BETWEEN
TUPLE AND DICTIONARY
DIFFERENCE BETWEEN TUPLE AND
DICTIONARY
TUPLE DICTIONARY
Order is maintained. Ordering is not
guaranteed.
They are immutable Values in a dictionary can
be changed.
They can hold any
type, and types can be
mixed.
Every entry has a key and
a value
DIFFERENCE BETWEEN TUPLE AND
DICTIONARY
TUPLE DICTIONARY
Elements are accessed
via numeric (zero
based) indices
Elements are accessed
using key's values
There is a difference in
syntax and looks easy
to define tuple
Differ in syntax, looks bit
complicated when
compare with Tuple or
lists
Class Test
PROGRAMS ON TUPLE
BELLOW AVERAGE
PROGRAMS
1. Write a Python program to create a tuple.
#Create an empty tuple
x = ()
print(x)
#Create an empty tuple with tuple() function
#built-in Python
tuplex = tuple()
print(tuplex)
TUPLE - BELLOW AVERAGE
PROGRAMS
2. Write a Python program to create a tuple
with
different data types
#Create a tuple with different data types
tuplex = ("tuple", False, 3.2, 1)
print(tuplex)
TUPLE - BELLOW AVERAGE
PROGRAMS
3. Write a Python program to unpack a tuple
in several variables
#create a tuple
tuplex = 4, 8, 3
print(tuplex)
n1, n2, n3 = tuplex
#unpack a tuple in variables
print(n1 + n2 + n3)
#the number of variables must be equal to
the number of items of the tuple
n1, n2, n3, n4= tuplex
TUPLE - BELLOW AVERAGE
PROGRAMS
TUPLE - AVERAGE PROGRAMS
4 Write a Python program to find the index
of an item of a tuple.
#create a tuple
tuplex = tuple("index tuple")
print(tuplex)
#get index of the first item whose value is
passed as parameter
index = tuplex.index("p")
print(index)
#define the index from which you want to
search
index = tuplex.index("p", 5)
TUPLE - AVERAGE PROGRAMS
print(index)
#define the segment of the tuple to be
searched
index = tuplex.index("e", 3, 6)
print(index)
#if item not exists in the tuple return
ValueError Exception
index = tuplex.index("y")
TUPLE - AVERAGE PROGRAMS
5. Write a Python program to add an item in
a tuple.
#create a tuple
tuplex = (4, 6, 2, 8, 3, 1)
print(tuplex)
#tuples are immutable, so you can not add
new elements
#using merge of tuples with the + operator
you can add an element and it will create a
new tuple
tuplex = tuplex + (9,)
print(tuplex)
TUPLE - AVERAGE PROGRAMS
5. Write a Python program to add an item in
a tuple.
#adding items in a specific index
tuplex = tuplex[:5] + (15, 20, 25) + tuplex[:5]
print(tuplex)
#converting the tuple to list
listx = list(tuplex)
#use different ways to add items in list
listx.append(30)
tuplex = tuple(listx)
print(tuplex)
TUPLE - AVERAGE PROGRAMS
TUPLE – CLASS WORK/ HOME WORK
PROGRAMS
6. Write a Python program to convert a tuple
to a string.
7. Write a Python program to get the 4th
element and 4th element from last of a
tuple.
8. Write a Python program to find the
repeated items of a tuple.
9. Write a Python program to check whether
an element exists within a tuple.
TUPLE - AVERAGE PROGRAMS
Class Test
Time: 40 Min Max Marks: 20
1. What is tuple? give example? 02
2. Write a python script to access a tuple? 05
3. Explain 2 built in methods of?
dictionary? 10
1. Differentiate between tuple and list? 05
Chapter 13 Tuples.pptx

More Related Content

PPTX
Chapter 13 Tuples.pptx
PPTX
Chapter 17 Tuples
PDF
Python Tuple.pdf
PPTX
Tuples-and-Dictionaries.pptx
PPTX
Tuples.pptx
PPTX
Lecture 09.pptx
PPTX
Tuples class 11 notes- important notes for tuple lesson
Chapter 13 Tuples.pptx
Chapter 17 Tuples
Python Tuple.pdf
Tuples-and-Dictionaries.pptx
Tuples.pptx
Lecture 09.pptx
Tuples class 11 notes- important notes for tuple lesson

Similar to Chapter 13 Tuples.pptx (20)

PDF
Tuple in Python class documnet pritened.
PDF
Python Is Very most Important for Your Life Time.
PPTX
UNIT-3 python and data structure alo.pptx
PDF
tuples chapter (1).pdfhsuenduneudhhsbhhd
PPT
Programming in Python Lists and its methods .ppt
PPTX
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PPTX
Python Collections
PDF
updated_tuple_in_python.pdf
PDF
Python tuple
PDF
Python tuples and Dictionary
PDF
Python data handling notes
PPTX
tupple.pptx
PDF
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
PDF
Python Tuples
PPT
List.ppt
PPTX
Tuples in python better understanding with slides
PPTX
tuple in python is an impotant topic.pptx
PPT
PPTX
PRESENTATION ON TUPLES.pptx
Tuple in Python class documnet pritened.
Python Is Very most Important for Your Life Time.
UNIT-3 python and data structure alo.pptx
tuples chapter (1).pdfhsuenduneudhhsbhhd
Programming in Python Lists and its methods .ppt
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
Python Collections
updated_tuple_in_python.pdf
Python tuple
Python tuples and Dictionary
Python data handling notes
tupple.pptx
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
Python Tuples
List.ppt
Tuples in python better understanding with slides
tuple in python is an impotant topic.pptx
PRESENTATION ON TUPLES.pptx
Ad

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Hybrid model detection and classification of lung cancer
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
A Presentation on Artificial Intelligence
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
A Presentation on Touch Screen Technology
PPTX
Tartificialntelligence_presentation.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Mushroom cultivation and it's methods.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Hybrid model detection and classification of lung cancer
Encapsulation_ Review paper, used for researhc scholars
A comparative analysis of optical character recognition models for extracting...
A Presentation on Artificial Intelligence
Zenith AI: Advanced Artificial Intelligence
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
A novel scalable deep ensemble learning framework for big data classification...
1 - Historical Antecedents, Social Consideration.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
A Presentation on Touch Screen Technology
Tartificialntelligence_presentation.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Web App vs Mobile App What Should You Build First.pdf
Encapsulation theory and applications.pdf
OMC Textile Division Presentation 2021.pptx
Mushroom cultivation and it's methods.pdf
Ad

Chapter 13 Tuples.pptx

  • 2. Computational Thinking and Programming XI Computer Science (083) Board : CBSE Courtesy CBSE
  • 4. After studying this lesson, students will be able to: Understand the need of Tuples; Solve problems by using Tuples;  Get clear idea about Tuple functions; and Understand the difference between list, dictionary and tuples. LEARNING OUTCOMES
  • 6. A tuple is a sequence of values, which can be of any type and they are indexed by integer. Tuples are just like list, but we can’t change values of tuples in place. Thus tuples are immutable. The index value of tuple starts from 0. A tuple consists of a number of values separated by commas. For example: >>> T=10, 20, 30, 40 >>> print (T) (10, 20, 30, 40) WHAT IS TUPLE?
  • 14. CHECK IF ITEM EXISTS
  • 15. CHECK IF ITEM EXISTS OUTPUT
  • 19. REMOVING A TUPLE You cannot remove or delete or update items in a tuple. Tuples are unchangeable, so you cannot remove items from it, but you can delete the tuple completely: NOTE: TUPLES ARE IMMUTABLE
  • 21. TUPLE METHODS Python provides two built-in methods that you can use on tuples. 1. count() Method 2. index() Method
  • 22. TUPLE METHODS 1. count() Method Return the number of times the value appears in the tuple Count() method returns total no times ‘banana’ present in the given tuple
  • 23. TUPLE METHODS 2. index() Method index() Method returns index of “banana” i.e 1 index() Method
  • 25. DIFFERENCE BETWEEN LIST AND TUPLE LIST TUPLE Syntax for list is slightly different comparing with tuple Syntax for tuple is slightly different comparing with lists Weekdays=[‘Sun’,’Mo n’, ‘wed’,46,67] type(Weekdays) class<‘lists’> twdays = (‘Sun’, ‘mon', ‘tue', 634) type(twdays) class<‘tuple’> List uses [ and ] (square brackets) to bind the elements. Tuple uses rounded brackets( and ) to bind the elements.
  • 26. DIFFERENCE BETWEEN LIST AND TUPLE LIST TUPLE List can be edited once it is created in python. Lists are mutable data structure. A tuple is a list which one cannot edit once it is created in Python code. The tuple is an immutable data structure More methods or functions are associated with lists. Compare to lists tuples have Less methods or functions.
  • 28. DIFFERENCE BETWEEN TUPLE AND DICTIONARY TUPLE DICTIONARY Order is maintained. Ordering is not guaranteed. They are immutable Values in a dictionary can be changed. They can hold any type, and types can be mixed. Every entry has a key and a value
  • 29. DIFFERENCE BETWEEN TUPLE AND DICTIONARY TUPLE DICTIONARY Elements are accessed via numeric (zero based) indices Elements are accessed using key's values There is a difference in syntax and looks easy to define tuple Differ in syntax, looks bit complicated when compare with Tuple or lists
  • 31. PROGRAMS ON TUPLE BELLOW AVERAGE PROGRAMS
  • 32. 1. Write a Python program to create a tuple. #Create an empty tuple x = () print(x) #Create an empty tuple with tuple() function #built-in Python tuplex = tuple() print(tuplex) TUPLE - BELLOW AVERAGE PROGRAMS
  • 33. 2. Write a Python program to create a tuple with different data types #Create a tuple with different data types tuplex = ("tuple", False, 3.2, 1) print(tuplex) TUPLE - BELLOW AVERAGE PROGRAMS
  • 34. 3. Write a Python program to unpack a tuple in several variables #create a tuple tuplex = 4, 8, 3 print(tuplex) n1, n2, n3 = tuplex #unpack a tuple in variables print(n1 + n2 + n3) #the number of variables must be equal to the number of items of the tuple n1, n2, n3, n4= tuplex TUPLE - BELLOW AVERAGE PROGRAMS
  • 35. TUPLE - AVERAGE PROGRAMS
  • 36. 4 Write a Python program to find the index of an item of a tuple. #create a tuple tuplex = tuple("index tuple") print(tuplex) #get index of the first item whose value is passed as parameter index = tuplex.index("p") print(index) #define the index from which you want to search index = tuplex.index("p", 5) TUPLE - AVERAGE PROGRAMS
  • 37. print(index) #define the segment of the tuple to be searched index = tuplex.index("e", 3, 6) print(index) #if item not exists in the tuple return ValueError Exception index = tuplex.index("y") TUPLE - AVERAGE PROGRAMS
  • 38. 5. Write a Python program to add an item in a tuple. #create a tuple tuplex = (4, 6, 2, 8, 3, 1) print(tuplex) #tuples are immutable, so you can not add new elements #using merge of tuples with the + operator you can add an element and it will create a new tuple tuplex = tuplex + (9,) print(tuplex) TUPLE - AVERAGE PROGRAMS
  • 39. 5. Write a Python program to add an item in a tuple. #adding items in a specific index tuplex = tuplex[:5] + (15, 20, 25) + tuplex[:5] print(tuplex) #converting the tuple to list listx = list(tuplex) #use different ways to add items in list listx.append(30) tuplex = tuple(listx) print(tuplex) TUPLE - AVERAGE PROGRAMS
  • 40. TUPLE – CLASS WORK/ HOME WORK PROGRAMS
  • 41. 6. Write a Python program to convert a tuple to a string. 7. Write a Python program to get the 4th element and 4th element from last of a tuple. 8. Write a Python program to find the repeated items of a tuple. 9. Write a Python program to check whether an element exists within a tuple. TUPLE - AVERAGE PROGRAMS
  • 42. Class Test Time: 40 Min Max Marks: 20 1. What is tuple? give example? 02 2. Write a python script to access a tuple? 05 3. Explain 2 built in methods of? dictionary? 10 1. Differentiate between tuple and list? 05