Page 49 - IPP-11
P. 49
45. Define the body of the loop.
Ans. The sets of statements which get executed on the test condition becoming true are defined as the body
of the loop.
46. What is an exit control loop? Give an example.
Ans. An exit control loop is a loop which checks for a condition to be true or false at the time of exit from the
loop. For example, do...while.
47. What is the purpose of using a for loop?
Ans. The for loop is used for definite/fixed number of iterations.
48. What are the supported data types in Python?
Ans. Python has five standard data types—
(i) Numbers
(ii) String
(iii) List
(iv) Tuple
(v) Dictionary
49. Is Python object-oriented?
Ans. Yes, Python is an Object-oriented Programming language.
50. What is the purpose of break statement?
Ans. The break statement is used to forcefully terminate the loop execution where it has been given.
51. What is an exception in Python?
Ans. An error that happens during the execution of the code/program is termed as an exception. For example,
Syntax errors, runtime errors, like division by zero, are examples of exceptions in Python.
52. Name the method that works reverse of split() method in strings.
Ans. join() method
53. Define a string.
Ans. A string is a sequence of characters. Strings are immutable in Python, i.e., they cannot be modified once
created.
54. 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,
mutable type as you can add or delete elements from the list any time.
55. 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.
56. What does append() function do?
Ans. It simply adds/appends an element to the end of the list.
57. 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.
58. What does the item() method of dictionary return?
Ans. The item() method returns a list of dictionary (key:value) pairs as tuples.
59. 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.
60. Differentiate between hstack and vstack?
Ans. hstack is used to stack (join) arrays in sequence horizontally (column-wise). On the other hand, vstack is
used to stack arrays in sequence vertically (row-wise).
4