Python Basics
Python Basics - Important Points
31. | Which of the following is the correct way to define a function in Python? |
---|
A. function_name(arguments):
B. def function_name(arguments):
C. function_name(arguments)
D. None of the above
View Answer Discuss Work SpaceAnswer: option b
Explanation:
32. | What is the output of the following code? x = [1, 2, 3] y = x y[0] = 4 print(x) |
---|
A. [1, 2, 3]
B. [4, 2, 3]
C. [1, 4, 3]
D. [1, 2, 4]
View Answer Discuss Work SpaceAnswer: option b
Explanation:
In Python, variables that reference lists are actually pointing to the same list in memory. So when the value of y[0] is changed to 4, the value of x[0] is also changed.
33. | Which of the following is the correct way to remove an element from a list in Python? |
---|
A. list.remove(element)
B. list.pop(element)
C. del list[element]
D. All of the above
View Answer Discuss Work SpaceAnswer: option a
Explanation:
34. | Which of the following is the correct way to open a file in Python? |
---|
A. file = open(filename, "r")
B. file = open("r", filename)
C. file = open(filename, "w")
D. None of the above
View Answer Discuss Work SpaceAnswer: option a
Explanation:
35. | Which of the following is the correct way to sort a list in descending order in Python? |
---|
A. list.sort(reverse=True)
B. list.sort(reverse=False)
C. list.reverse()
D. None of the above
View Answer Discuss Work SpaceAnswer: option a
Explanation: