Python Basics
Python Basics - Important Points
21. | Which of the following is the correct way to open a file for writing in Python? |
---|
A. file = open("example.txt", "w")
B. file = open("example.txt", "r")
C. file = open("example.txt", "a")
D. file = open("example.txt", "x")
View Answer Discuss Work SpaceAnswer: option a
Explanation:
22. | Which of the following is the correct way to remove an element from a list in Python? |
---|
A. list.delete(element)
B. list.remove(element)
C. list.pop(element)
D. list.clear(element)
View Answer Discuss Work SpaceAnswer: option b
Explanation:
23. | Which of the following is the correct way to concatenate two lists in Python? |
---|
A. list1.add(list2)
B. list1.append(list2)
C. list1 + list2
D. list1.extend(list2)
View Answer Discuss Work SpaceAnswer: option c
Explanation:
24. | Which of the following is the correct way to open a file in Python? |
---|
A. open_file("example.txt")
B. open("example.txt")
C. file.open("example.txt")
D. with open("example.txt") as file:
View Answer Discuss Work SpaceAnswer: option b
Explanation:
25. | Which of the following is the correct way to define a class in Python? |
---|
A. class my_class():
B. define class my_class:
C. def my_class():
D. class my_class:
View Answer Discuss Work SpaceAnswer: option d
Explanation: