Q: What will be the output of the following Python code? def f(i, values = []): values.append(i) return values f(1) f(2) v = f(3) print(v)
Solution: Execute in the shell to verify
Q: What will be the output of the following Python code? numbers = [1, 2, 3, 4] numbers.append([5,6,7,8]) print(len(numbers))
Solution: A list is passed in append so the length is 5.
Q: To which of the following the “in” operator can be used to check if an item is in it?
Solution: In can be used in all data structures.
Q: What will be the output of the following Python code? list1 = [1, 2, 3, 4] list2 = [5, 6, 7, 8] print(len(list1 + list2))
Solution: + appends all the elements individually into a new list.
Q: What will be the output of the following Python code? def addItem(listParam): listParam += [1] mylist = [1, 2, 3, 4] addItem(mylist) print(len(mylist))
Solution: + will append the element to the list.
Q: What will be the output of the following Python code? def increment_items(L, increment): i = 0 while i < len(L): L[i] = L[i] + increment i = i + 1 values = [1, 2, 3] print(increment_items(values, 2)) print(values)
Solution: Execute in the shell to verify.
You Have Score    | /6 |