These Python multiple-choice questions and their answers will help you strengthen your grip on the subject of Python. You can prepare for an upcoming exam or job interview with these 800+ Python MCQs.
So scroll down and start answering.
A. A statement.
B. A lambda.
C. A closure.
D. A suite.
E. An expression.
A. [[1, 2], [1, 2], [1, 2]]
B. Compilation error
C. [1, 2, 3, 4, 5, 6]
D. [6, 6, 6, 6, 6, 6]
E. [[1, 2], [3, 4], [5, 6]]
A. sys
B. re
C. regularexpressions
D. regexp
A. **
B. ^
C. Both are correct.
D. None are correct.
A. System administrators' toolkits for Python
B. GUI programming toolkits for Python
C. Test suites for Python
D. Names of popular Python repositories
A. Single quotes are for short strings. Double quotes are for long strings.
B. There is no difference.
C. Double quotes are for constants. Single quotes are for variables.
D. In Python you can use only single quotes.
A. '9'
B. [9]
C. '333'
D. [3, 3, 3]
A. ()
B. None of these
C. ""
D. {}
A. Always
B. Never
A. Yes
B. No
A. Always
B. Never
A. py
B. pl
C. pt
D. pie
E. pil
A. 0
B. 1
C. -2,147,483,648
D. -1
A. Repeatedly execute a block of code
B. Conditionally execute a block of code
C. Execute code from more than one place in a program
A. "a"
B. ret("a")
C. return "a"
D. a
A. bear
B. tiger
C. penguin
D. zebra
A. //
B. {
C. /*
D. #
A. print 'fred'
B. println('fred')
C. cout << "fred" << endl;
D. write('fred')
A. CPython
B. IronPython
C. Jython
D. PyPy
A. False
B. True
A. False
B. True
A. use
B. package
C. external
D. import
A. All are correct.
B. The name of the operating system where your Python code is run.
C. The largest integer the machine's architecture supports.
D. The Python interpreter's version number.
A. It's configurable.
B. 100000
C. 100
D. 10000
E. 1000000
A. This expression will result in a syntax error.
B. Undefined
C. 0
D. 1
A. None.
B. set
C. list
D. dictionary
E. All three.
A. >
B. #
C. $
D. >>>
A. Dynamic.
B. Inverse.
C. Loading.
D. Proportional.
E. Static.
A. Yes, but only in the interactive shell.
B. Yes, but only when the program runs on a remote server.
C. Yes.
D. No.
A. Counter.
B. List.
C. Dictionary.
D. Tuple.
E. Set.
A. Returns the status of all printers installed on the network.
B. Evaluates its parameters and writes the resulting objects to standard output.
C. Allows users to input data.
D. Prints the source code on the default printer.
A. len
B. length
C. size
D. Tuplen for tuples, listlen for lists, strlen for strings
A. <!-- text -->
B. # text
C. // text
D. /* text */
E. ^^ text ^^
A. "
B. """
C. '''
D. All of these are correct,
E. '
A. Repeats string1 string2 times (string2 must be in numeric format).
B. Concatenates string1 and string2.
C. It's a syntax error.
D. Adds string1 to string2 (both must be in numeric format).
A. "hello" * 2
B. "hello" ** 2
C. len ( "hello" )
D. "hello" + "hello"
A. A statement which allows you to choose one variant from a given set
B. A collection of elements, each identified by an index
C. An object which may contain some data
D. An object containing data whose value cannot be altered by the program
A. !=
B. isn't
C. =/=
D. ><
E. >=
A. With the "function" keyword.
B. With the "def" keyword.
C. With function prototypes declared in header files.
D. With "do function ... done".
A. Only HTTP
B. Only HTTP, FTP, POP3, IMAP4
C. None of them
D. All of them
A. There is no way to pass parameters to a class instance.
B. Specifying those parameters after the class name.
C. Specifying those parameters in the definition of an __init__ method of the class.
D. Writing the desired values after the class name when the class instance is created.
A. To remove a function from a list given its name.
B. To remove an item from a list given its index.
C. To delete a file from the file system given its path.
D. To delete a user if you are a privileged user.
A. False
B. True
A. x = list{'1', '2', '3'}
B. x = list(1, 2, 3)
C. x = {'1', '2', '3'}
D. x = [1, 2, 3]
E. x = new list (1, 2, 3)
A. elseif:
B. elif:
C. if:
D. else:
A. import date date.pause(5)
B. import time time.sleep(5)
C. import date date.pause(5.0)
A. 2
B. None and the system generates an error (exception)
C. None
D. 1
E. 3
A. l.len()
B. len(l)
C. length(l)
D. l.length()
A. i mod j
B. i % j
C. i // j
D. i / j
A. for i in range(11): print i
B. for( x = 0; x < 11; x++) printf("%s",x);
C. while x < 10: print x
D. for i in range(10): print i
A. 0 to n-1
B. 0 to n
C. n-1 to n
D. Syntax error: missing arguments
A. x["quizful"][] = "python test"
B. x["quizful"].append("python test")
C. x["quizful"].add("python test")
D. x["quizful"] += "python test"
A. Use 4 spaces per indentation level
B. Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value
C. CapWords for class names, lowercase for function names
D. All of these
E. Limit all lines to a maximum of 79 characters
A. list_.flip()
B. list_ = list_[-1::]
C. list_.reverse()
D. list_[-1:-len(a)]
A. ['Sir Robin', 'Sir Gawaine', 'Sir Not Appearing in this film']
B. 4
C. ['Sir Robin', 'Sir Gawaine', 'Sir Not Appearing in this film', 'rabbits']
D. ['Sir Robin', 'Sir Gawaine', 'Sir Not Appearing in this film', 'cb', 'rabbits']
E. True
A. floatize
B. float
C. int_to_float
D. int2float
A. Lists have no length limit.
B. Lists can be nested, tuples not.
C. Lists can be mutated, while tuples cannot.
D. Lists cannot be mutated, while tuples can.
E. Only list can be subclassed.
A. :
B. nothing
C. end of line
A. mydict.update('foo', 'Goodbye')
B. mydict[foo] = 'Goodbye'
C. mydict.foo.update('Goodbye')
D. mydict['foo'] = 'Goodbye'
E. mydict.foo = 'Goodbye'
A. Multi-indexing
B. Pieces
C. Pathfinding
D. Slices
A. No, there is no elif statement in Python
B. Yes
C. No
D. Yes, unless it is used in place of an else statement
A. array
B. string
C. tuple
D. list
A. 2 spaces
B. 8 spaces
C. 1 tab
D. 4 spaces
A. 2
B. 1.5
C. 1
A. Yes
B. Yes, but only when not in Python's interactive shell
C. Yes, but only in Python's interactive shell
D. No
A. An object which is a sequence of characters
B. Any text put in double-quotes
C. The same thing as a statement, just an argument
D. A line of source code
A. pass
B. return
C. yield
D. continue
E. break
A. True
B. False
A. Tuples are created with parentheses and lists are create with square brackets.
B. Tuples are created with square brackets and lists are create with square with parentheses.
C. Tuples can contain no more than 16 elements, lists can contain more than that.
D. Lists are changeable sequences of data, while tuples are not changeable.
A. The result will be an integer.
B. The result of this operation is undefined.
C. The result will be a long number.
D. Python will warn you about a type mismatch and ask if you want to convert an integer to a long.
E. This operation will result in an overflow error.
A. Math.pow( 5, 3)
B. 5 ^ 3
C. pow( "5 ^ 3")
D. 5 ** 3
A. '.org'
B. IndexError: string index out of range
C. 'http'
D. 'python.org'
E. 'docs'
A. False
B. True
A. 444444
B. This statement will result in a syntax error.
C. "a*b"
D. 24
A. Nothing. It can be used when a statement is needed syntactically.
B. Jumps to the top of the closest enclosing loop.
C. There is no such statement in Python.
D. It passes control flow of the program to the debugger.
E. It is a function which asks the user to enter a password.
A. open('file').readline()
B. open('file').read('\n')
C. open('file').read()
D. open('file').readlines()
A. 'F'
B. 'B'
C. IndexError exception
D. 'A'
A. This expression will result in a syntax error.
B. ('x.x')
C. ('xxx', 'abcxxxabc', 'axxxxa')
D. ('xxx')
A. myList.has_item(myVar)
B. myList.contains(myVar)
C. myVar.exists(myList)
D. myVar in myList
E. myVar.in(myList)
A. the __class__ function
B. the __init__ function
C. global variables
D. the init function
A. 'pip' does not have an 'install' subcommand
B. $PIP_PKG_DIR - your local database of Python packages (by default /var/cache/pip on UNIX and C:\pypackaging\pip on Windows)
C. PyPI - the Python Package Index
D. packages.debian.org - the Debian package archive
E. the lowest-latency Sourceforge download mirror
A. Provides static documentation about an object.
B. reformats a source code according to python formatting rules
C. dynamically alters the functionality of a function, method, or class.
D. is a sub-class on object in an inherited class
A. It is impossible to provide a default value to a function's parameter.
B. By writing the desired value in parentheses after the parameter's name.
C. By writing the desired value in curly brackets after the parameter's name.
D. By writing an equal sign after the parameter's name and then the desired value.
A. x = last(aList)
B. x = aList[-1]
C. x = aList.pop()
D. x = aList.last()
A. def, lambda
B. def, defun
C. def, letrec
D. def, proc
E. def, import
A. cat file_
B. for line in file_: print line
C. while True: if not line: break line = file_.readline()
D. print file_
A. str
B. float
C. int
D. double
E. bool
A. Code that is written after this statement is executed only when the module is used directly.
B. Code that is written after this statement is ignored by the interpreter, so comments are usually added after it.
C. Some of the viruses that infect Python files do not affect modules with such a statement.
D. This code prevents a module from being executed directly.
A. Both of them.
B. Only +
C. Only *
D. Neither.
A. fopen 'dino', 'r'
B. open('dino', 'r')
C. open 'dino', 'r'
D. open('dino', 'rb')
A. d
B. g
C. G
D. u
A. Yes, but only for string variables
B. Yes, but only for numeric variables
C. It is always possible.
D. No.
A. 'lambda lambda lambda'
B. An anonymous function.
C. A syntax error.
D. 13
E. 4
A. Any Python program which imports external modules.
B. All Python programs that are available on the computer.
C. A folder with module files that can be imported together.
D. Any folder with Python source code files in it.
A. "Python _".find("_", "Supremacy")
B. "Python _".replace("_", "Supremacy")
C. "Python _".substitute("_", "Supremacy")
A. You cannot extend classes in Python
B. SubclassName is subclass of BasicClassName
C. class SubclassName(BasicClassName):
D. class BasicClassName(SubclassName):
A. There is no switch operator in Python
B. switch?
C. switch
D. switch:
A. the packaging tools for Python
B. utility functions for calculating distance
C. utility functions for higher order math functions.
A. TRUE
B. 1
C. 0
D. False
A. RR'
B. 'lower'
C. an AttributeError exception
D. rr
E. 'rr'