Python Programming Quiz & Flashcards
Master Python Programming concepts with our interactive study cards featuring 51 practice Quiz questions and 52 flashcards to boost your exam scores and retention in Computer Science.
Quiz Complete!
0%
0
You are currently studying 10 out of 51 Questions
Sign in to unlock allCreate your own study sets
Turn any PDF, lecture notes, or ChatGPT conversation into interactive quizzes in seconds.
51 Multiple Choice Questions and Answers on Python Programming
Revise and practice with 51 comprehensive MCQ on Python Programming, featuring detailed explanations to deepen your understanding of Computer Science Quiz concepts. Perfect for quick review and exam preparation.
1 What does the 'len()' function do in Python?
The 'len()' function is used to return the number of items in an object.
2 Which of the following is used to create an empty dictionary?
An empty dictionary is created using curly braces '{}'.
3 What is the output of 'print(type([]))'?
The empty square brackets '[]' denote a list, so the type is '<class 'list'>'.
4 How do you create a comment in Python?
Comments in Python are created using the '#' symbol.
5 What is the result of '5 // 2' in Python?
The '//' operator performs floor division, which results in '2' for '5 // 2'.
6 Which keyword is used to handle exceptions?
The 'try' keyword initiates a block of code that will attempt an operation which may raise an exception.
7 What is the role of 'self' in class methods?
'self' refers to the instance of the class and is used to access variables and methods associated with the instance.
8 What does the 'break' statement do?
The 'break' statement exits the current loop prematurely.
9 Which of the following is a mutable type?
Lists are mutable, meaning their elements can be changed.
10 What is the purpose of the 'isinstance()' function?
'isinstance()' checks if an object is an instance or subclass thereof of a class.
11 How do you open a file for writing in Python?
The 'w' mode in open() is used to open a file for writing.
12 What keyword is used to define a function?
Functions are defined in Python using the 'def' keyword.
13 Which function is used to convert a string to lowercase?
The 'lower()' method is used to convert a string to lowercase.
14 Which of the following data structures does not allow duplicate elements?
Sets do not allow duplicate elements.
15 What does the 'pop()' method do in a list?
The 'pop()' method removes and returns the last item from a list if no index is specified.
16 Which operator is used for exponentiation in Python?
The '**' operator is used for exponentiation in Python.
17 Which statement about Python is true?
Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming.
18 What is a correct syntax to output 'Hello World' in Python?
The correct syntax for outputting text in Python is using the 'print()' function.
19 Which of the following is not a valid Python variable name?
Variable names cannot start with a number, making '2variable' invalid.
20 What will 'print(3 * 'abc')' output?
Multiplying a string by a number repeats the string, resulting in 'abcabcabc'.
21 What is the purpose of the 'dir()' function?
'dir()' is used to list the properties and methods of an object.
22 Which method is used to add an element to the end of a list?
The 'append()' method adds an element to the end of a list.
23 What is the output of 'print(type(3.14))'?
The number 3.14 is a floating-point number, so its type is '<class 'float'>'.
24 What does the 'zip()' function do?
The 'zip()' function combines two or more iterables element-wise into tuples.
25 What will 'bool([])' return?
An empty list is considered False in a boolean context.
26 Which keyword is used to create an alias for a module?
The 'as' keyword is used to create an alias for a module during import.
27 What is the output of 'print(5 > 3 and 2 < 4)'?
Both conditions are true, so the 'and' operation returns True.
28 Which function converts a list of strings to a single string with elements separated by a comma?
The 'join()' method concatenates list elements into a single string separated by commas.
29 Which operator checks if two variables point to the same object?
The 'is' operator checks for identity, i.e., if two variables point to the same object.
30 What is the output of 'print('2' + '3')'?
The '+' operator concatenates two strings, so '2' + '3' becomes '23'.
31 What will be the result of '3 % 2'?
'3 % 2' gives the remainder of the division, which is 1.
32 How do you find the maximum value in a list?
The 'max()' function returns the maximum value in a list.
33 What does 'setdefault()' do in a dictionary?
The 'setdefault()' method returns the value of a key if it exists, otherwise inserts the key with a default value.
34 What will 'print(type({}))' output?
An empty '{}' is interpreted as a dictionary, so the type is '<class 'dict'>'.
35 What is the result of 'not True and False'?
'not True' evaluates to False, and 'False and False' results in False.
36 Which of the following is a built-in function in Python?
'len()' is a built-in function that returns the number of items in an object.
37 What does 'range(5)' return?
'range(5)' returns a sequence from 0 to 4.
38 What will be the output of 'print(bool(0))'?
The integer 0 is considered False in a boolean context.
39 Which method is used to remove all elements from a list?
The 'clear()' method removes all elements from a list.
40 What is the output of '5 ** 2'?
The '**' operator raises the first number to the power of the second, so '5 ** 2' is 25.
41 Which of these is a correct way to create a function that takes no arguments and returns 10?
In Python, 'def func(): return 10' correctly defines a function with no arguments.
42 What will 'print(3 != 3)' output?
The '!=' operator checks for inequality, so '3 != 3' is False.
43 What is the correct syntax for a conditional expression?
The syntax 'a if condition else b' is used for conditional expressions in Python.
44 How do you convert a list to a tuple?
The 'tuple()' function converts a list to a tuple.
45 What is the output of 'print(3 * 'abc')'?
Multiplying a string by a number repeats the string, resulting in 'abcabcabc'.
46 What is the output of 'print(10 // 3)'?
'10 // 3' performs floor division, which results in '3'.
47 Which function is used to read all lines of a file as a list?
The 'readlines()' method reads all lines of a file and returns them as a list.
48 Which statement about Python lists is true?
Python lists are mutable and can contain elements of different types.
49 What will 'print(type((1,)))' output?
The syntax '(1,)' creates a tuple with a single element.
50 What is the result of '3 and 0'?
The 'and' operator returns the first falsy value, which is '0' in this case.
51 Which of the following is a correct way to declare a multi-line string?
Both triple single quotes and triple double quotes can be used to declare multi-line strings.
uizGPT