Python Basics
Python Basics - Important Points
36. | Which of the following is the correct way to concatenate two strings in Python? |
---|
A. string1.join(string2)
B. string1.concat(string2)
C. string1 + string2
D. All of the above
View Answer Discuss Work SpaceAnswer: option c
Explanation:
37. | What is the output of the following code? x = 3 if x > 5:print("x is greater than 5") elif x > 2:print("x is greater than 2") else:print("x is less than or equal to 2") |
---|
A. x is greater than 5
B. x is greater than 2
C. x is less than or equal to 2
D. None of the above
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The variable x is greater than 2, so the code in the elif block will be executed.
38. | What is the output of the following code? x = 2 y = 5 z = x + y print("The sum of", x, "and", y, "is", z) |
---|
A. The sum of 2 and 5 is 7
B. The sum of x and y is z
C. The sum of x and y is 7
D. None of the above
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The print() function is used to output the sum of x and y as a string with the appropriate values included.