Tuples in Python | Tuples Functions and methods in python | CBSE Class XII Computer science

Tuples  in Python | Tuples Functions and methods in python

Hi guys in this blog we are going to discuss about Tuples in Python
The Tuples are depicted through parentheses i.e., round brackets, e.g., tuples in Python

  1. () #tuple with no member, empty tuple
  2. (7,) #tuple with one member(
  3. 1, 2, 3) #tuple of integers
  4. (1, 2.5, 3.7, 9) #tuple of numbers (integers and floating)
  5. (a, B, C)#tuple of characters
  6. (a, 1, b, 3.5, 'zero') #tuple of mixed value types
  7. (One, Two, Three') #tuple of string

Tuples are immutable sequences ie, you cannot change elements of a tuple in place.


Creating Tuples

To create a tuple, put a number of expressions, separated by commas in parentheses. That is create a tuple you can write in the form given below:
T=()
T=(value, ...)
This construct is known as a tuple display construct.

Creating Empty Tuple

The empty tuple is (). You can also create an empty tuple

T= tuple()

Creating Single Element Tuple

Making a tuple with a single element is tricky because if you just give a single element in round brackets, Python considers it a value only, e.g.,
>>>t=(1)

Tuple Functions and Methods

  • len()
  • max()
  • min()
  • index()
  • count ()
  • tuple()

Post a Comment

If you any doubts, Please let me know

Previous Post Next Post