menu

Python Basics

Python Basics - Important Points


16.

What is the output of the following code?

x = 5
print("x =", x)

A. x = 5

B. x

C. 5

D. x, 5

Discuss Work Space

Answer: option a

Explanation:

The print() function outputs the value of the variable x along with the text "x =".


17.

What is the output of the following code?

x = "Hello World"
print(x[4])

A. H

B. e

C. l

D. o

Discuss Work Space

Answer: option d

Explanation:

Python uses zero-based indexing for strings, so x[4] is the 5th character of the string, which is "o".


18. Which of the following is the correct syntax for a for loop in Python?

A. for i in range(10)

B. for i = 1 to 10

C. for i in (1, 10)

D. for i in [1, 2, 3, 4, 5]

Discuss Work Space

Answer: option a

Explanation:

The range() function generates a sequence of numbers from 0 up to (but not including) the specified value, which can be used with a for loop to iterate a specific number of times.

19.

What is the result of the following code?

x = ["apple", "banana", "cherry"]
print(len(x))

A. 3

B. 5

C. 6

D. p

Discuss Work Space

Answer: option a

Explanation:

The len() function returns the number of items in a list, which is 3 in this case.


20.

What is the output of the following code?

x = 5
y = "10"
print(x + y)

A. 15

B. 510

C. TypeError

D. None of the above

Discuss Work Space

Answer: option c

Explanation:

Python does not allow adding a number and a string together using the + operator, so a TypeError will be raised.



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

Unlock Your Future

Join Now
Worried for Placements in 2025?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2025

Join Now