What is the output of the code?
✅ (0, 'P')(1, 'Y')(2, 'T')(3, 'H')(4, 'O')(5, 'N')
❌ ('PYTHON')
❌ ('P','Y','T','H','O','N')
❌ Error
❌ None of the mentioned
Explanation:
Enumerate is a built-in function that iterates through a sequence and gets the index and values simultaneously. Enumerate ( ) returns a pair value of index values and its list element.
✅ (0, 'P')(1, 'Y')(2, 'T')(3, 'H')(4, 'O')(5, 'N')
❌ ('PYTHON')
❌ ('P','Y','T','H','O','N')
❌ Error
❌ None of the mentioned
Explanation:
Enumerate is a built-in function that iterates through a sequence and gets the index and values simultaneously. Enumerate ( ) returns a pair value of index values and its list element.
What is the output of the code?
❌ True False
✅ False True
❌ False False
❌ True True
❌ Error
Explanation:
The objects with same contents share the same object in the python library but this is not true for custom-defined immutable classes.
❌ True False
✅ False True
❌ False False
❌ True True
❌ Error
Explanation:
The objects with same contents share the same object in the python library but this is not true for custom-defined immutable classes.
What will be displayed by the code?
❌ 1 1
❌ 1 44
❌ 3 1
✅ 3 44
❌ Error
❌ None of the above
Explanation:
The value of t=3 is passed in funcion f(value,values) , v [list] is passed as values in the same function. The v is stored in values and values[0]=44 , changes the value at index[‘0’] in the list hence v=[44,2,3].
❌ 1 1
❌ 1 44
❌ 3 1
✅ 3 44
❌ Error
❌ None of the above
Explanation:
The value of t=3 is passed in funcion f(value,values) , v [list] is passed as values in the same function. The v is stored in values and values[0]=44 , changes the value at index[‘0’] in the list hence v=[44,2,3].
What is the output of the program?
❌ Specific ZeroDivisionError Specific ZeroDivisionError
❌ Specific ZeroDivisionError Finally ZeroDivisionError
❌ Specific IndexError General IndexError Finally ZeroDivisionError
✅ Finally IndexError Specific ZeroDivisionError Finally ZeroDivisionError
❌ Finally IndexError Specific ZeroDivisionError General ZeroDivisionError Finally ZeroDivisionError
❌ Finally IndexError Specific ZeroDivisionError
❌ None of the above
Explanation:
"finally" block of code is always executed whether the exception occurs or not. If exception occurs, the except block is executed first matched by exception type.
General try and except concept:
First try clause is executed i.e. the code between try and except clause.
If there is no exception, then only try clause will run, except clause will not get executed.
If any exception occurs, the try clause will be skipped and except clause will run.
If any exception occurs, but the except clause within the code doesn’t handle it, it is passed on to the outer try statements. If the exception is left unhandled, then the execution stops.
A try statement can have more than one except clause.
❌ Specific ZeroDivisionError Specific ZeroDivisionError
❌ Specific ZeroDivisionError Finally ZeroDivisionError
❌ Specific IndexError General IndexError Finally ZeroDivisionError
✅ Finally IndexError Specific ZeroDivisionError Finally ZeroDivisionError
❌ Finally IndexError Specific ZeroDivisionError General ZeroDivisionError Finally ZeroDivisionError
❌ Finally IndexError Specific ZeroDivisionError
❌ None of the above
Explanation:
"finally" block of code is always executed whether the exception occurs or not. If exception occurs, the except block is executed first matched by exception type.
General try and except concept:
First try clause is executed i.e. the code between try and except clause.
If there is no exception, then only try clause will run, except clause will not get executed.
If any exception occurs, the try clause will be skipped and except clause will run.
If any exception occurs, but the except clause within the code doesn’t handle it, it is passed on to the outer try statements. If the exception is left unhandled, then the execution stops.
A try statement can have more than one except clause.
What is the output of the code?
❌ ['top', 'quiz']
❌ ['TOP', 'QUIZ']
❌ ['top', 'quiz', 'TOP', 'QUIZ']
❌ [None, None]
❌ []
✅ None of the above
Explanation:
The loop does not terminate and will run without end because new elements are being added to the list in each iteration.
❌ ['top', 'quiz']
❌ ['TOP', 'QUIZ']
❌ ['top', 'quiz', 'TOP', 'QUIZ']
❌ [None, None]
❌ []
✅ None of the above
Explanation:
The loop does not terminate and will run without end because new elements are being added to the list in each iteration.
What will be the output of the code snippet?
❌ [[], 'abc', [0], 1, 0]
✅ ['abc', [0], 1]
❌ ['abc', 0, 1]
❌ [0, 1]
❌ [1]
❌ ['abc']
❌ None of the above
Explanation:
The above code filters all the elements from list a, which evaluates to boolean value true, i.e. any non empty string, list or non-zero value is accepted.
❌ [[], 'abc', [0], 1, 0]
✅ ['abc', [0], 1]
❌ ['abc', 0, 1]
❌ [0, 1]
❌ [1]
❌ ['abc']
❌ None of the above
Explanation:
The above code filters all the elements from list a, which evaluates to boolean value true, i.e. any non empty string, list or non-zero value is accepted.
What will be the value of 'result'?
✅ [1, 3, 5, 7, 8]
❌ [1, 7, 8]
❌ [1, 2, 4, 7, 8]
❌ Error
❌ None of the above
Explanation:
Here, 'result' is a list which is extending three times. When first time 'extend' function is called for 'result', the inner code generates a generator object, which is further used in 'extend' function. This generator object contains the values which are in 'list1' only (not in 'list2' and 'list3'). Same is happening in second and third call of 'extend' function in these generator object contains values only in 'list2' and 'list3' respectively. So, 'result' variable will contain elements which are only in one list (not more than 1 list).
✅ [1, 3, 5, 7, 8]
❌ [1, 7, 8]
❌ [1, 2, 4, 7, 8]
❌ Error
❌ None of the above
Explanation:
Here, 'result' is a list which is extending three times. When first time 'extend' function is called for 'result', the inner code generates a generator object, which is further used in 'extend' function. This generator object contains the values which are in 'list1' only (not in 'list2' and 'list3'). Same is happening in second and third call of 'extend' function in these generator object contains values only in 'list2' and 'list3' respectively. So, 'result' variable will contain elements which are only in one list (not more than 1 list).