Lists and Tuples in Python

Chapter Checkup

Note: To Download all chapter  PDF for class 6, 7, 8; Scroll below—-

A.Fill in the Blanks.

1.A list can contain ….unlimited…. Elements.

2.Tuples are…..faster….than lists.

3.Lists are ….mutable.

4.Tuples are….immutable.

5.The ….reverse… attribute of sort() method is used to reverse the order of the list.

B. Tick the correct Option.

1.The list.pop() function will :

               ans. b. remove the last element from the list.

  1. Which of the following are true about Python lists?

              ans . a. There is no limit to the size of a list.

  1. List L is given below:

           L = [0,1,2,3,4]

 Choose the correct answer to delete the element 3 from the list.

   Ans. b. L.remove(3)

  1. Which of the following is mutable?

Ans. b. List

  1. What will be the output of the given code?

          tuple =(1,8,7,5,4,8,5)

          x = tuple.count(5)

          print(x)

Ans . b. 2

C. Who Am I?

1.I am a method that helps to sort a list.

Ans: sort()

  1. I am a collection of values which is ordered and unchangeable.

Ans : tuple

  1. I am a dynamic and change-oriented collection of values.

Ans: List

  1. I am a method that helps to add an element at the end of the list.

Ans : append()

  1. I am an operator that helps to replicate a tuple.

Ans: * (Asteric)

D. Write T for True and F for False.

1.The sort() function is used to reverse the order of the list. FALSE

2.You cannot directly insert or delete data items in a tuple. TRUE

3.Lists are immutable. FALSE

4.The list allows duplicate values. TRUE

5.Lists cannot store different types of elements. FALSE

E. Answer the following.

1.Explain any three characteristics of a list.

Ans:

  • The characteristics of the lists are given below:
  • Ordered: In a list, the values or items have a defined order, and this order does not change. If you add new values to a list, they are placed at the end of the list.
  • Accessed via the Index: You can access list elements using an index, which starts at 0. Hence, the first element of a list is present at index 0, not 1.
  • Allows Duplicate Values: A list can contain duplicate values. Since values are indexed in a list, it can have items with the same value but a different index.
  • Mutable: The meaning of mutable is “liable to change”. In Python, list items are mutable. It means elements of the list can be modified, individual elements can be replaced, and the order of elements can be changed even after the list has been created.
  • Variable Size: Lists can store a variable number of elements, allowing you to store and manage different quantities of data.
  •  
  • 2. Write a code to create a tuple with a single element.

Ans

                  mytuple = (‘Aakash’, )

3. Differentiate between pop() and remove() with a suitable example.

pop(): This method is used to remove the element at the specified position.

  • For example, remove the third element from the

                list = [3, 4, 9, 3, 8, 9]

                list.pop(2)

                print(list)

Output: [3, 4, 3, 8, 9]

  • [Hint: The third element has an index 2.]

remove(): This method is used to remove the first occurrence of the specified element.

For example, remove 3 from the list = [3, 4, 9, 3, 8, 9]

List.remove(3)

Output: [4, 9,3,8,9]

Write three differences between list and tuple.

                                                  List

  • Lists are mutable
  • You can easily insert or delete data items in a list.
  • Lists have several built in methods.
  • Lists are generally slightly slower than tuples because of their mutability
  • Lists are created using square brackets []
  • Example : list1 = [1, 2, 3]

                                            Tuple

  • Tuples are immutable.
  • You cannot directly insert or delete data items in a tuple.
  • Due to immutability, a tuple is does not have many built in methods.
  • Tuples are faster than lists.
  • Tuples are created using parenthesis ()
  • Example: tuple1 = (1, 2, 3)

5. Discuss any three characteristics of a tuple.

Ans

  • Characteristics of Tuples

The characteristics of tuples are given below:

  • Ordered: In a tuple, the values or items have a defined order, and this order does not change.
  • Accessed via the Index: The tuple element can be accessed via the index. It means that the tuple index always starts with 0.
  • Immutable: The tuple items are immutable. It means that we cannot add, modify, or remove items in a tuple after it has been created.
  • Allows Duplicate Values: A tuple can contain duplicate values. Since values are indexed in a tuple, it can have items with the same value and a different index.

Leave a Comment

Your email address will not be published. Required fields are marked *

×