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 3 MCQs Strings and Lists; Tuples and Dictionaries

ECE181 — Introduction To Python 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 string a compound data type Easy

    Why is a string considered a compound data type in Python?

  2. Question 2 of 60 length Easy

    Which function returns the number of characters in a string?

  3. Question 3 of 60 accessing elements Easy

    What is the index of the first character in a Python string?

  4. Question 4 of 60 string slices Easy

    What is the result of "python"[0:3]?

  5. Question 5 of 60 string traversal Easy

    Which loop is commonly used to traverse each character of a string?

  6. Question 6 of 60 comparison Easy

    What does the expression "apple" == "apple" evaluate to?

  7. Question 7 of 60 find function Easy

    What does "hello".find("l") return?

  8. Question 8 of 60 find function Easy

    What does the find() method return when the substring is not present?

  9. Question 9 of 60 looping and counting Easy

    What is a common use of a counter variable while looping through a string?

  10. Question 10 of 60 list values Easy

    Which of the following correctly creates a list of three numbers?

  11. Question 11 of 60 length Easy

    What does len([10, 20, 30, 40]) return?

  12. Question 12 of 60 membership Easy

    What does the expression 3 in [1, 2, 3] evaluate to?

  13. Question 13 of 60 operations Easy

    What is the result of [1, 2] + [3, 4]?

  14. Question 14 of 60 slices Easy

    What is the result of [10, 20, 30, 40][1:3]?

  15. Question 15 of 60 deletion Easy

    Which keyword is used to remove an item from a list by its index?

  16. Question 16 of 60 list and for loops Easy

    What is printed by for x in [1, 2, 3]: print(x)?

  17. Question 17 of 60 list parameters and nested list Easy

    What is a nested list?

  18. Question 18 of 60 tuples Easy

    Which symbol pair is typically used to create a tuple?

  19. Question 19 of 60 operations on tuples Easy

    What key property makes tuples different from lists?

  20. Question 20 of 60 creating dictionary Easy

    Which of the following correctly creates a dictionary?

  21. Question 21 of 60 string slices Medium

    What is the output of the following code?

    Python
    s = "Programming"
    print(s[2:8:2])

  22. Question 22 of 60 string traversal Medium

    What does the following loop print?

    Python
    word = "abc"
    for ch in word:
        print(ch * 2, end="")

  23. Question 23 of 60 find function Medium

    What is the result of the following code?

    Python
    s = "banana"
    print(s.find("na"))

  24. Question 24 of 60 comparison Medium

    What is the output of the following comparison?

    Python
    print("apple" < "banana")

  25. Question 25 of 60 looping and counting Medium

    How many times does the letter s appear based on this code?

    Python
    text = "mississippi"
    count = 0
    for c in text:
        if c == "s":
            count += 1
    print(count)

  26. Question 26 of 60 length Medium

    What is the output of the following code?

    Python
    s = "Hello, World!"
    print(len(s))

  27. Question 27 of 60 string a compound data type Medium

    Which statement about Python strings is correct?

  28. Question 28 of 60 operations Medium

    What is the output of the following code?

    Python
    result = [1, 2] + [3, 4] * 2
    print(result)

  29. Question 29 of 60 slices Medium

    What does the following code print?

    Python
    nums = [10, 20, 30, 40, 50]
    print(nums[-3:-1])

  30. Question 30 of 60 membership Medium

    What is the output of the following code?

    Python
    data = [[1, 2], [3, 4]]
    print(3 in data)

  31. Question 31 of 60 deletion Medium

    What is the value of nums after this code runs?

    Python
    nums = [1, 2, 3, 4, 5]
    del nums[1:3]
    print(nums)

  32. Question 32 of 60 accessing elements Medium

    What does the following code print?

    Python
    matrix = [[1, 2, 3], [4, 5, 6]]
    print(matrix[1][2])

  33. Question 33 of 60 list and for loops Medium

    What is the output of the following code?

    Python
    nums = [1, 2, 3, 4]
    total = 0
    for n in nums:
        total += n * n
    print(total)

  34. Question 34 of 60 list parameters and nested list Medium

    What does the following code print?

    Python
    def modify(lst):
        lst.append(99)
    
    nums = [1, 2, 3]
    modify(nums)
    print(nums)

  35. Question 35 of 60 tuples Medium

    What happens when the following code is executed?

    Python
    t = (1, 2, 3)
    t[0] = 10
    print(t)

  36. Question 36 of 60 operations on tuples Medium

    What is the output of the following code?

    Python
    t = (1, 2) * 3
    print(len(t))

  37. Question 37 of 60 creating dictionary Medium

    What is the output of the following code?

    Python
    d = dict([("a", 1), ("b", 2)])
    print(d["b"])

  38. Question 38 of 60 adding-modifying-retrieving dictionary values Medium

    What does the following code print?

    Python
    d = {"x": 1}
    d["y"] = 2
    d["x"] = 5
    print(d)

  39. Question 39 of 60 deleting items Medium

    What is the output of the following code?

    Python
    d = {"a": 1, "b": 2, "c": 3}
    del d["b"]
    print(list(d.keys()))

  40. Question 40 of 60 dictionary methods Medium

    What is the output of the following code?

    Python
    d = {"a": 1, "b": 2}
    print(d.get("c", 0))

  41. Question 41 of 60 string slices Hard

    What is the output of the following code?

    Python
    s = "programming"
    print(s[::-2])

  42. Question 42 of 60 comparison Hard

    Which expression evaluates to True in Python 3?

  43. Question 43 of 60 find function Hard

    What does the following print?

    Python
    s = "mississippi"
    print(s.find("ss", 3))

  44. Question 44 of 60 looping and counting Hard

    What is the value of count after this loop?

    Python
    s = "aAbBcCaA"
    count = 0
    for ch in s:
        if ch.lower() == 'a':
            count += 1
    print(count)

  45. Question 45 of 60 string traversal Hard

    What is the output?

    Python
    s = "abcde"
    result = ""
    for i in range(len(s)):
        result += s[i] * i
    print(result)

  46. Question 46 of 60 operations Hard

    What is printed?

    Python
    a = [1, 2, 3]
    b = a * 2
    b[0] = 99
    print(a[0], b[0])

  47. Question 47 of 60 list parameters and nested list Hard

    What is the output?

    Python
    def modify(lst):
        lst = lst + [4]
        lst.append(5)
    x = [1, 2, 3]
    modify(x)
    print(x)

  48. Question 48 of 60 slices Hard

    What is the result?

    Python
    lst = [0, 1, 2, 3, 4, 5]
    lst[1:4] = [10, 20]
    print(lst)

  49. Question 49 of 60 deletion Hard

    What is the output?

    Python
    lst = [10, 20, 30, 40, 50]
    del lst[1:4:2]
    print(lst)

  50. Question 50 of 60 list and for loops Hard

    What does this print?

    Python
    matrix = [[1, 2], [3, 4], [5, 6]]
    total = 0
    for row in matrix:
        total += row[-1]
    print(total)

  51. Question 51 of 60 membership Hard

    What is the output?

    Python
    nested = [[1, 2], [3, 4]]
    print(3 in nested, [3, 4] in nested)

  52. Question 52 of 60 accessing elements Hard

    What is printed?

    Python
    grid = [[0]*3]*3
    grid[0][0] = 1
    print(grid)

  53. Question 53 of 60 tuples Hard

    Which of the following creates a tuple containing a single integer element?

  54. Question 54 of 60 operations on tuples Hard

    What is the output?

    Python
    t = (1, [2, 3], 4)
    t[1].append(5)
    print(t)

  55. Question 55 of 60 creating dictionary Hard

    What does the following produce?

    Python
    d = dict(zip("abc", [1, 2, 3, 4]))
    print(d)

  56. Question 56 of 60 adding-modifying-retrieving dictionary values Hard

    What is printed?

    Python
    d = {'x': 1}
    print(d.get('y', 0) + d.setdefault('y', 5))
    print(d)

  57. Question 57 of 60 deleting items Hard

    What is the output?

    Python
    d = {'a': 1, 'b': 2, 'c': 3}
    val = d.pop('b')
    res = d.pop('z', -1)
    print(val, res, len(d))

  58. Question 58 of 60 dictionary methods Hard

    What does this print?

    Python
    d = {'a': 1, 'b': 2}
    d.update({'b': 20, 'c': 30})
    print(sum(d.values()))

  59. Question 59 of 60 operations on dictionary Hard

    What is the output?

    Python
    d = {1: 'a', 2: 'b'}
    for k in list(d.keys()):
        d[k*10] = d[k]
    print(len(d))

  60. Question 60 of 60 length Hard

    What is printed?

    Python
    s = "a\tb\nc"
    print(len(s))

That's unit 3

Answer a few questions and your score shows up here.