Skip to main content

Command Palette

Search for a command to run...

Basics of Python-6

Published
2 min read
Basics of  Python-6
P

Hello, I'm Priya Chakraborty, a dedicated B.Tech student in Electrical Engineering at Siliguri Institute Of Technology. I'm an enthusiastic learner, constantly seeking to expand my skill set and knowledge base. With a solid foundation in programming languages such as C, R, Python, and MySQL, I'm poised to tackle complex technical challenges.

But my passions extend beyond the realm of engineering. I'm also an aspiring content writer, driven by a curiosity to communicate ideas, both technical and non-technical, in a way that captivates and educates.

My journey is defined by a relentless pursuit of self-improvement, coupled with strong communication skills. I believe in the power of continuous learning and the importance of sharing knowledge.

Day 6

Tuple :

Tuple is an in-built data type in python and is used to collect objects, by separation of commas.

  1. Tuples are mutable.

  2. We use the '( )' operator to denote a tuple

  3. Indexing is the same as the list

Let's solve a few problems on tuples:

  1. Find the maximum and minimum element in the tuple :
n=(1,5,3,2,0)
print(sorted(n))
print(max(n))
print(min(n))

output:

  1. To find the sum of the tuple element:
n=(7,9,3,4)
sum=0
for i in n:
    sum=sum+i 
print(sum)

output:

Problems :

  1. Write a python program to find Row-wise element Addition in Tuple Matrix

  2. Write a python program to update each element in the tuple list

  3. Write a python program to multiply Adjacent elements

  4. Write a python program to join Tuples if the similar initial element

  5. Write a python program to find All pair combinations of 2 tuples

  6. Write a python program to remove Tuples of Length K

  7. Write a python program to remove Tuples from the List having every element as None

  8. Write a python program to sort a list of tuples by the second Item

  9. Write a python program to sort Tuples by Total digits

  10. Write a python program to find Elements frequency in Tuple

  11. Write a python program to filter Range Length Tuples

  12. Write a python program to assign Frequency to Tuples

  13. Write a python program to find Records with Value at the K index

Let's have a look at the basic difference between list and tuple :

LISTTUPLE
we use '[ ]' operatorwe use '( )' operator
List is mutableTuple is immutable

In my next blog, you will get to about set data types.

Thank you!

More from this blog

Priya's blog

46 posts

Python Developer@Codeclause Mentee @Trailhead Salesforce Content Executive @GDSC SIT'22-23 Google Women Techmakers Ambassador @Google WTM Coreteam @ GirlScript Kolkata

Basics of Python-6