Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 1 MCQs Python basics

ECAP776 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Introduction Easy

    Which file extension is commonly used for Python source files?

  2. Question 2 of 60 Introduction Easy

    Which function displays output on the screen in Python?

  3. Question 3 of 60 Introduction Easy

    Which symbol begins a single-line comment in Python?

  4. Question 4 of 60 Introduction Easy

    Which function accepts input from the user in Python?

  5. Question 5 of 60 Introduction Easy

    Which of the following is a valid Python variable name?

  6. Question 6 of 60 Data types and operators Easy

    Which Python data type stores whole numbers?

  7. Question 7 of 60 Data types and operators Easy

    What is the data type of the value 3.14 in Python?

  8. Question 8 of 60 Data types and operators Easy

    Which operator is used for exponentiation in Python?

  9. Question 9 of 60 Data types and operators Easy

    What is the result of 10 % 3?

  10. Question 10 of 60 Data types and operators Easy

    Which operator checks whether two values are equal?

  11. Question 11 of 60 Control statements Easy

    Which keyword begins a conditional statement in Python?

  12. Question 12 of 60 Control statements Easy

    Which keyword provides an alternative when an if condition is false?

  13. Question 13 of 60 Control statements Easy

    Which loop is commonly used to iterate over a sequence in Python?

  14. Question 14 of 60 Control statements Easy

    Which statement immediately exits the nearest loop?

  15. Question 15 of 60 Control statements Easy

    Which statement skips the rest of the current loop iteration?

  16. Question 16 of 60 Functions Easy

    Which keyword is used to define a function in Python?

  17. Question 17 of 60 Functions Easy

    What is the purpose of the return statement in a function?

  18. Question 18 of 60 Functions Easy

    In def greet(name):, what is name?

  19. Question 19 of 60 Functions Easy

    How do you call a function named show that takes no arguments?

  20. Question 20 of 60 Functions Easy

    Which built-in function returns the number of items in a list?

  21. Question 21 of 60 Introduction Medium

    What is printed by the following code?

    x = 10

    x = "10"

    print(x * 2)

  22. Question 22 of 60 Introduction Medium

    A file named tools.py contains:

    print("loaded")

    if __name__ == "__main__":

    print("running")

    What is printed when another program executes import tools?

  23. Question 23 of 60 Introduction Medium

    What is the output of this simultaneous assignment?

    a, b = 2, 3

    a, b = b, a + b

    print(a, b)

  24. Question 24 of 60 Introduction Medium

    What does this program print?

    total = 4

    Total = 7

    TOTAL = total + Total

    print(TOTAL)

  25. Question 25 of 60 Data types and operators Medium

    What is printed by print(type((5,)).__name__, type((5)).__name__)?

  26. Question 26 of 60 Data types and operators Medium

    What is the output of print(-7 // 3, -7 % 3)?

  27. Question 27 of 60 Data types and operators Medium

    What is printed by the following code?

    a = [1, 2]

    b = a

    c = a[:]

    b.append(3)

    print(c, a)

  28. Question 28 of 60 Data types and operators Medium

    What is the output of this dictionary operation?

    d = {"a": 1, "b": 2, "a": 3}

    print(len(d), d["a"])

  29. Question 29 of 60 Data types and operators Medium

    Which set is produced by {1, 2, 3} & {2, 3, 4} | {4, 5}?

  30. Question 30 of 60 Data types and operators Medium

    What value is printed by print(-2 ** 2 + 2 ** 3)?

  31. Question 31 of 60 Control statements Medium

    What is printed by the following loop?

    total = 0

    for n in range(2, 10, 3):

    total += n

    print(total)

  32. Question 32 of 60 Control statements Medium

    Which letter is printed by this conditional?

    x = 8

    if x % 2 == 0 and x > 10:

    print("A")

    elif x % 2 == 0 or x > 10:

    print("B")

    else:

    print("C")

  33. Question 33 of 60 Control statements Medium

    What value is printed after this loop?

    n = 20

    count = 0

    while n > 1:

    n //= 2

    count += 1

    print(count)

  34. Question 34 of 60 Control statements Medium

    What is the final value of result?

    result = []

    for n in range(2, 10):

    if n % 3 == 0:

    continue

    if n > 7:

    break

    result.append(n)

  35. Question 35 of 60 Control statements Medium

    What is printed by these nested loops?

    count = 0

    for i in range(1, 4):

    for j in range(1, 4):

    if i == j:

    continue

    count += 1

    print(count)

  36. Question 36 of 60 Functions Medium

    What is printed by the following code?

    def add_item(item, items=[]):

    items.append(item)

    return items

    print(add_item(1))

    print(add_item(2))

  37. Question 37 of 60 Functions Medium

    What is the output of this program?

    x = 10

    def change():

    x = 3

    return x

    print(change(), x)

  38. Question 38 of 60 Functions Medium

    What value is returned by calculate(3, 4, 5, 6)?

    def calculate(a, b=2, *numbers):

    return a + b + sum(numbers)

  39. Question 39 of 60 Functions Medium

    What is printed by this function call?

    def divide_parts(n):

    return n // 2, n % 2

    q, r = divide_parts(7)

    print(q, r)

  40. Question 40 of 60 Functions Medium

    What is the value of ordered after this statement?

    words = ["pear", "fig", "apple", "kiwi"]

    ordered = sorted(words, key=lambda word: (len(word), word))

  41. Question 41 of 60 Introduction Hard

    What is printed by the following code?

    Python
    a = [0, 0]
    i = 0
    i, a[i] = 1, 7
    print(a, i)

  42. Question 42 of 60 Introduction Hard

    Assuming no future imports, what is printed?

    Python
    def f(x: int = '3') -> int:
        return x * 2
    
    print(f(), f(4))

  43. Question 43 of 60 Introduction Hard

    What happens when this code is executed?

    Python
    x = 10
    
    def f(flag):
        if flag:
            x = 20
        return x
    
    print(f(False))

  44. Question 44 of 60 Introduction Hard

    In Python 3.10 or later, what is printed by this module-level code?

    Python
    x = 100
    s = [x := x + i for i in range(3)]
    print(x, s, 'i' in globals())

  45. Question 45 of 60 Introduction Hard

    A file named m.py contains only print(__name__). What does it print when run directly, and what does it print when first imported as m by another script?

  46. Question 46 of 60 Data types and operators Hard

    What is printed by the following code?

    Python
    x = [1, 2]
    y = x
    x += [3]
    z = x
    x = x + [4]
    print(y, z, x, y is z, z is x)

  47. Question 47 of 60 Data types and operators Hard

    What is printed?

    Python
    result = 0 or [] or 'py' and 5
    print(result, type(result).__name__)

  48. Question 48 of 60 Data types and operators Hard

    What is printed by this dictionary code?

    Python
    d = {True: 'A', 1: 'B', 1.0: 'C'}
    print(len(d), list(d.keys()), d[1])

  49. Question 49 of 60 Data types and operators Hard

    What is printed by these slices?

    Python
    a = [0, 1, 2, 3, 4, 5]
    print(a[5:0:-2], a[::-2])

  50. Question 50 of 60 Data types and operators Hard

    What exact text is printed?

    Python
    def f(v):
        print(v, end='')
        return v
    
    print(f(3) < f(2) < f(1))

  51. Question 51 of 60 Control statements Hard

    What exact text is printed?

    Python
    for i in range(3):
        try:
            if i == 1:
                continue
            print(i, end='')
        finally:
            print('F', end='')

  52. Question 52 of 60 Control statements Hard

    What is printed?

    Python
    n = 3
    while n:
        n -= 1
        if n == 1:
            break
    else:
        print('E', end='')
    print(n)

  53. Question 53 of 60 Control statements Hard

    What exact text is printed?

    Python
    for i in range(4):
        for j in range(4):
            if i * j > 2:
                break
        else:
            print(i, end='')

  54. Question 54 of 60 Control statements Hard

    What is printed by the following code?

    Python
    def g(x):
        try:
            r = 10 // x
        except ZeroDivisionError:
            r = 0
        else:
            r += 1
        finally:
            r *= 2
        return r
    
    print(g(2), g(0))

  55. Question 55 of 60 Control statements Hard

    What is printed by this comprehension?

    Python
    print([i for i in range(6) if i % 2 if i % 3])

  56. Question 56 of 60 Functions Hard

    What is printed?

    Python
    def f(x, acc=[]):
        acc += [x]
        return acc
    
    a = f(1)
    b = f(2, [])
    c = f(3)
    print(a, b, c, a is c)

  57. Question 57 of 60 Functions Hard

    What is printed by these functions?

    Python
    funcs = []
    for i in range(3):
        funcs.append(lambda x=i: x + i)
    i = 10
    print([f() for f in funcs])

  58. Question 58 of 60 Functions Hard

    In Python 3.10 or later, which call raises TypeError?

    Python
    def f(a, /, b=2, *, c=3):
        return a + b + c

  59. Question 59 of 60 Functions Hard

    What is printed after applying these decorators?

    Python
    def deco(tag):
        def outer(fn):
            def inner():
                return tag + fn() + tag
            return inner
        return outer
    
    @deco('A')
    @deco('B')
    def f():
        return 'X'
    
    print(f())

  60. Question 60 of 60 Functions Hard

    What is printed by this generator code?

    Python
    def gen():
        yield 1
        return 7
    
    g = gen()
    a = next(g)
    try:
        next(g)
    except StopIteration as e:
        b = e.value
    print(a, b)

That's unit 1

Answer a few questions and your score shows up here.