21. You have imported the re module into Python with the code import re. Which code searches the device_ids string variable for a pattern of "r15\w+"?

  • re.findall(device_ids, “r15\w+”)
  • findall(“r15\w+”, device_ids)
  • re.findall(“r15\w+”, device_ids)
  • findall(device_ids, “r15\w+”)

22. Which method adds input to the end of a list?

  • .append()
  • .lower()
  • .insert()
  • .index()

23. What is the output of the following code?

print(len("125"))

  • 3
  • 10
  • 8
  • 5

24. Which line of code returns a copy of the string "bmoreno" as "BMORENO"?

  • print(“bmoreno”.upper())
  • print(upper.”bmoreno”())
  • print(upper(“bmoreno”))
  • print(“bmoreno”(upper))

25. What is the index of the character "c" in the string "encryption"?

  • 2
  • 3
  • 1
  • 4

26. What is the output of the following code?

username_list = ["elarson", "bmoreno", "tshah"]

device_id_list = ["us2c0R5", "2R78TBR", "bt3MIEz"]

print(username_list + device_id_list)

  • [“elarson”, “us2c0R5”, “bmoreno”, “2R78TBR”, “tshah”, “bt3MIEz”]
  • [“us2c0R5”, “2R78TBR”, “bt3MIEz”, “elarson”, “bmoreno”, “tshah”]
  • An error message
  • [“elarson”, “bmoreno”, “tshah”, “us2c0R5”, “2R78TBR”, “bt3MIEz”]

27. A variable named my_list contains the list [1,2,3,4]. Which line of code removes the last element in the list?

  • remove (my_list, 3)
  • remove(my_list, 4)
  • my_list.remove(3)
  • my_list.remove(4)

28. What module do you need to import to use regular expressions in Python?

  • os
  • time
  • re
  • csv

Shuffle Q/A 3

29. What is the result when .upper() is applied to a string?

  • The character that appears most frequently in the string is extracted from it and returned.
  • The value of the string is reassigned to the value of the string in the line preceding it.
  • The value of the string is reassigned to contain all uppercase letters.
  • A copy of the string is returned with all uppercase letters.

30. What is the output of the following code?

approved_users = ["bmoreno", "elarson", "tshah", "eraab"]

print(approved_users[1])

  • “elarson”
  • [“bmoreno”, “elarson”, “tshah”, “eraab”, 1]
  • “bmoreno”
  • [1, “bmoreno”, “elarson”, “tshah”, “eraab”]

Leave a Reply