Page 48 - PYTHON-11
P. 48
67. State the use of split() function in Python.
Ans. The use of split() function in Python is that it breaks a string into substrings using the defined separator. It
does not return the specified substring separator element present in the string.
68. Name the method that works as the reverse of split() method in strings.
Ans. join() method.
69. Define a string.
Ans. A string is a sequence of characters. Strings are immutable in Python, i.e., they cannot be modified once
created.
70. Define a list in Python. Why is it mutable and dynamic in nature?
Ans. A list in Python is an ordered collection of items which may belong to any data type. A list is dynamic,
immutable type as you can add or delete elements from the list any time.
71. What happens when an element gets deleted from a list?
Ans. When we remove an element from a list, the size or length of the list decreases by 1 position.
72. What does append() function do in existing list?
Ans. The append() function simply adds/appends an element to the end of the existing list.
73. Can we reverse the elements of a tuple in Python?
Ans. Tuple being immutable in nature, its reverse is not possible.
74. Which function returns the frequency of a particular element in tuple?
Ans. count().
75. What is a dictionary?
Ans. A Python dictionary is a collection of key-value pairs. The elements in a dictionary are indexed by keys which
must be unique.
76. What does the items() method of dictionary return?
Ans. The items() method returns a list of dictionaries (key-value) pairs as tuples.
77. Why are Python dictionaries also termed as mappings?
Ans. Python dictionaries are called mappings because these are like a collection that allows us to look up for
information associated with arbitrary keys.
78. Can list be used as key of dictionary? Justify your answer.
Ans. No, keys in a dictionary must be immutable. Since list is mutable, it cannot be used as key in dictionary.
79. What is the purpose of using update() method with dictionary?
Ans. The update() method modifies or updates dictionary with the elements from another dictionary or from
another sequence of key-value pairs.
80. Define a tuple.
Ans. A tuple is an immutable data type which cannot be changed. Tuples are represented by elements enclosed
with parentheses instead of square brackets.
81. Can tuples be nested?
Ans. Yes, tuples can be nested. You can add a tuple as an element to a tuple. It may contain other compound
objects as well including lists and dictionaries.
82. When would you prefer tuples over lists?
Ans. Tuples are preferred over lists when you need an immutable collection like in the case of creating dictionary
keys or as elements in a set. They are recommended to be used for representing data structures with a
fixed number of items like coordinates or records, where data should not change after creation.
83. Name a function which is same as find() but raises an exception if the substring is not present in the given
string.
Ans. index().
84. Name the built-in mathematical function/method that is used to return an absolute value of a number and
pie value.
Ans. To return an absolute value: abs()
To return a pie value: math.pi
V.6