Wednesday, 8 January 2020

CBSE Class 11 - Informatics Practices - Python Basics - List Manipulation (Part-1) - Question and Answers(#class11InformaticsPractices)(#eduvictors)

Python Basics - List Manipulation (Part-1)

Question and Answers
CBSE Class 11 - Informatics Practices & Computer Science

CBSE Class 11 - Informatics Practices - Python Basics - List Manipulation (Part-1) - Question and Answers(#class11InformaticsPractices)(#eduvictors)


Q1: What is a list in Python?

Answer: List is a collections of items and each item has its own index value. It is the most versatile datatype available in core Python which can be written as a list of comma-separated values (items) between square brackets.

e.g.
[] # empty list
[1,2,3,4] #list of integers
[2.0, 4.56, 8.91, ] #list of floats
['Sunday', 'Monday', 'Tuesday'] #list of floats
['Nikita', 16, 'Class 11', True, 86.7] # list of mixed values





Q2: What are different ways to create a list?

Answer: Creating a list is as simple as putting different comma-separated values between square brackets or you can use list( ) function.
e.g.
list1 = [3,5,9] #stores list of numbers
list2 = ['Hello', 123, True, 17.89] #stores list of mixed values
list3 = [] #creates empty list
list4 = list() #creates empty list
list5 = list("aeiou") #creates list as ['a', 'e', 'i', 'e', 'o']

CBSE Class 11 - Informatics Practices - Python Basics - List Manipulation (Part-1) - Question and Answers(#class11InformaticsPractices)(#eduvictors)


Q3: Are lists mutable or immutable?

Answer: Lists are mutable i.e. you can change the elements of a list.

Python List is mutable - CBSE Class 11 - Informatics Practices - Python Basics - List Manipulation (Part-1) - Question and Answers(#class11InformaticsPractices)(#eduvictors)


Q4: Can a list have another list? Give an example.

Answer: Yes, a list can contain other lists. Such a list is called nested list.
e.g.
>>> list1 = [1,2,[3,4],5,6]
Here list1[2] i.e. at position 2, stores a list [3,4]


Q5: How can an element of a list be accessed? Give an example to access values in lists.

Answer: List items can be accessed using its index position. To access individual elements of a list using the variable name for the list with an integer in square brackets. It supports zero-based indexing i.e. the first element of a list is position 0, the second position is 1 and so on.
e.g.
list1 = [3,4,5,6,7]
print(list[0]) #displays 3 at 0-position
print(list[2]) #displays 5 at 2-position.

It also supports negative indexing.
e.g.
print(list[-1]) #displays 7 i.e. first element from the last position.

Accessing Python List - CBSE Class 11 - Informatics Practices - Python Basics - List Manipulation (Part-1) - Question and Answers(#class11InformaticsPractices)(#eduvictors)


Q6: What is slicing in lists? Give an example.

Answer: List elements can be accessed in subparts called slicing.
e.g.
list1 = ['Jan', 'Feb', 'Mar', 'Apr', 'May']
list1[2:4] #displays ['Mar', 'Apr']



List Slicing - CBSE Class 11 - Informatics Practices - Python Basics - List Manipulation (Part-1) - Question and Answers(#class11InformaticsPractices)(#eduvictors)


Q7: How are lists different from strings when both are sequences?

Answer: The lists and strings are different in the following ways:
(i) The lists are mutable sequences while strings are immutable.

(ii) Strings store single type of elements, all characters while lists can store elements belonging to different types.

(iii) Strings store the individual characters in consecutive memory locations while list stores the references of its elements.



Q8: Give an example to iterate items of a list using for statement.

Answer: List elements can be accessed using looping statement.
e.g.
mylist = [10, 30, 19, 21, 29]
for item in mylist:
print(item)


Iterating a list - CBSE Class 11 - Informatics Practices - Python Basics - List Manipulation (Part-1) - Question and Answers(#class11InformaticsPractices)(#eduvictors)


Q9: Name the function used to find the number of items in a list. Give an example.

Answer: len( ) function.
e.g.
>>>list1 = [2,3,4,5,6]
>>>print(len(list1))
5


Q10: What is the output of the following code?
l1 = [1,3,5]
l2 = [1,3,5]
l3 = [1,3,6]
l1 == l2
l1 == l3
l2 < l3
l2 > l3

Answer:
True
False
True
False


☞See Also:
Python - String Manipulation (Part-1) Q & A
Python - String Manipulation (Part-2) Q & A

Buy Python Textbook: 
    ☞ Informatics Practices with Python: Textbook for CBSE Class 11
    ☞ Oswaal CBSE Question Bank Class 11 Informatics Practice Book Chapterwise & Topicwise Includes Objective Types & MCQ's (For March 2020 Exam)

No comments:

Post a comment

We love to hear your thoughts about this post!