menu

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

Discuss Work Space

Answer: option b

Explanation:

The def keyword is used to define a function in Python.

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]

Discuss Work Space

Answer: 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

Discuss Work Space

Answer: option a

Explanation:

The remove() method is used to remove an element from a list in Python.

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

Discuss Work Space

Answer: option a

Explanation:

The open() function is used to open a file in Python, with the mode specified as the second argument.

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

Discuss Work Space

Answer: option a

Explanation:

The sort() method can be used to sort a list in Python, with the reverse parameter set to True to sort in descending order.


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