Functions, Lists and Tuples

40 MCQs Covers functions, default and keyword arguments, *args, modules, libraries and packages. Also covers lists, tuples, strings, slicing and dictionaries

MCQs

40 questions · 35 min · 40 marks

Want to try first? Take the free Computer Science test: SDLC and Waterfall Model

Sample questions

The first 5 of 40. Try each one, then tap to see the answer.

  1. Question 1

    Which keyword is used to define a function?

    • Afunction
    • Bdef
    • Cdefine
    • Dfunc
    Show answer

    Answer: B

    Functions are defined with the def keyword.

  2. Question 2

    What is a default parameter?

    • AA parameter with no value
    • BA parameter that must be passed
    • CA special keyword
    • DA parameter with a pre-set value
    Show answer

    Answer: D

    If no argument is passed, the default value is used.

  3. Question 3

    What is the purpose of *args in Python?

    • AHandle many arguments
    • BReturn a list
    • CCreate variables
    • DMultiply strings
    Show answer

    Answer: A

    *args collects any number of positional arguments into a tuple.

  4. Question 4

    What does this code return: def add(a, b): return a + b, if add(2, 3) is called?

    • A23
    • Ba+b
    • C5
    • DError
    Show answer

    Answer: C

    The function returns the sum 2 + 3 = 5.

  5. Question 5

    What is the use of import in Python?

    • AExport values
    • BUse built-in libraries
    • CCall a function
    • DClose files
    Show answer

    Answer: B

    import brings a module or library into the program so its features can be used.

More tests in Python Programming

Practise with a free account

Save your scores, see which chapters need work, and keep a notebook of every question you got wrong.

Create free account