IKH

In Built Function

To get information

len()

  • Return number of elements present in the tuple.

Example

Python
t=(10,20,30,40)
print(len(t))

Output

PowerShell
4

count()

  • Return number of occurrences of given element in the tuple.

Example

Python
t=(10,20,10,10,20)
print(t.count(10))

Output

PowerShell
3

index()

  • Returns index of first occurrence of the given element. If the specified element is not available then we will get Value Error.

Example

Python
t=(10,20,10,10,20)
print(t.index(10))
print(t.index(30))

Output

PowerShell
0
ValueError: tuple.index(x): x not in tuple

min() and max()

  • These functions return min and max values according to default natural sorting order.

Example

Python
t=(40,10,30,20)
print(min(t))
print(max(t))

Output

PowerShell
10
40

To ordering elements

sorted()

  • Sort elements based on default natural sorting order.

Example

Python
t=(40,10,30,20)
t1=sorted(t)
print(t1)
print(t)

Output

PowerShell
[10, 20, 30, 40]
(40, 10, 30, 20)
  • We can sort according to reverse of default natural sorting order.

Example

Python
t=(40,10,30,20)
t1=sorted(t)
print(t1)
print(t)
t1=sorted(t,reverse=True)
print(t1)

Output

PowerShell
[10, 20, 30, 40]
(40, 10, 30, 20)
[40, 30, 20, 10]

Ungraded Questions

Get ready for an exhilarating evaluation of your understanding! Brace yourself as we dive into the upcoming assessment. Your active participation is key, so make sure to attend and demonstrate your knowledge. Let’s embark on this exciting learning journey together!


Name
Email
Phone

Report an error