menu

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")

Discuss Work Space

Answer: option a

Explanation:

The "w" parameter is used to open a file for writing in Python.

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)

Discuss Work Space

Answer: option b

Explanation:

The remove() method is used to remove the first occurrence of the specified element from a list in Python.

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)

Discuss Work Space

Answer: option c

Explanation:

The + operator is used to concatenate two lists in Python.

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:

Discuss Work Space

Answer: option b

Explanation:

The open() function is used to open a file in Python.

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:

Discuss Work Space

Answer: option d

Explanation:

The class keyword is used to define a class in Python.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now