Python Basics
Python Basics - Important Points
6. | Which of the following is the correct syntax for defining a function in Python? |
---|
A. function my_function():
B. def my_function():
C. define my_function():
D. func my_function():
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The def keyword is used to define a function in Python.
7. | Which of the following is NOT a comparison operator in Python? |
---|
A. ==
B. !=
C. <=
D. <>
View Answer Discuss Work SpaceAnswer: option d
Explanation:
The <> operator was used for inequality comparison in older versions of Python, but it is not supported in Python 3.x.
8. | Which of the following is NOT a comparison operator in Python? |
---|
A. ==
B. >
C. <
D. +
View Answer Discuss Work SpaceAnswer: option d
Explanation:
The + operator is used for addition in Python, not comparison.
9. | What is the output of the following code? print("Hello" + " World") |
---|
A. Hello
B. World
C. Hello World
D. Type Error
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The + operator concatenates two strings.
10. | Which of the following is the correct syntax for a while loop in Python? |
---|
A. while i in range(10):
B. while (i < 10)
C. while (i != 10)
D. while i = 10
View Answer Discuss Work SpaceAnswer: option b
Explanation:
A while loop in Python continues to execute as long as the specified condition is True.