Tag: Python
-
Python Questions and Answers – Matrix List Comprehension
Python Multiple Choice Questions & Answers (MCQs) focuses on “Matrix List Comprehension”. Q 1. Which of the following matrices will throw an error in Python?A. A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B. B = [[3, 3, 3] [4, 4, 4] [5, 5, 5]] C. C = [(1, 2, 4), (5,…
-
Python Multiple Choice Questions – List Comprehension
Python Multiple Choice Questions & Answers (MCQs) focuses on “List Comprehension”. Q 1. What will be the output of the following Python code snippet? k = [print(i) for i in my_string if i not in “aeiou”] A. prints all characters of my_string that aren’t vowelsB. prints all the consonants in my_stringC. prints all the vowels…
-
Python Questions and Answers – Lists – 4
Python Programming Questions & Answers focuses on “Lists”. Q 1. What will be the output of the following Python code? def f(i, values = []): values.append(i) return values f(1)f(2)v = f(3)print(v) A. [1] [2] [3]B. [1] [1, 2] [1, 2, 3]C. [1, 2, 3]D. 1 2 3 Show Answer Answer:-C. [1, 2, 3] Explanation Execute in…
-
Python Multiple Choice Quizs Question– String
Q 1. The output of executing string.ascii_letters can also be achieved by:A. string.ascii_lowercase_string.digitsB. string.lowercase_string.uppercaseC. string.lettersD. string.ascii_lowercase+string.ascii_uppercase Show Answer Answer:-D. string.ascii_lowercase+string.ascii_uppercase Explanation Execute in shell and check. Q 2 . What will be the output of the following Python code? A. ollehB. helloC. hD. o Show Answer Answer:-D. o Explanation 1 corresponds to the last index.…
-
Python Quizs Question and Answers – Formatting – 2
Q 1. The output of which of the codes shown below will be: “There are 4 blue birds.”?A. ‘There are %g %d birds.’ %4 %blueB. ‘There are %d %s birds.’ %(4, blue)C. ‘There are %s %d birds.’ %[4, blue]D. ‘There are %d %s birds.’ 4, blue Show Answer Answer:-B. ‘There are %d %s birds.’ %(4,…
-
Python Quizs Question and Answers – Decorators
Q 1. In the following Python code, which function is the decorator? def mk(x): def mk1(): print(“Decorated”) x() return mk1 def mk2(): print(“Ordinary”) p = mk(mk2) p() A. p()B. mk()C. mk1()D. mk2() Show Answer Answer:-B. mk() Explanation In the code shown above, the function mk() is the decorator. The function which is getting decorated is…
-
Python Quizs Question and Answers – Bitwise – 2
Q 1. It is not possible for the two’s complement value to be equal to the original value in any case.A. TrueB. False Show Answer Answer:-B. False Explanation In most cases the value of two’s complement is different from the original value. However, there are cases in which the two’s complement value may be equal…