Free PCAP Basic Questions and Answers — Questions and Answers
Question 1: What is the correct file extension for Python files?
- .pt
- .py (Correct answer)
- .python
- .pyt
Correct answer: .py
Python files have the extension .py
Question 2: Which of the following is a correct syntax to output "Hello World" in Python?
- print("Hello World") (Correct answer)
- echo "Hello World"
- Console. Write Line("Hello World")
- printf ("Hello World")
Correct answer: print("Hello World")
In Python, the print function is used to output text to the console.
Question 3: Which data type is used to store text in Python?
- int
- str (Correct answer)
- float
- bool
Correct answer: str
The str data type is used to store text in Python
Question 4: How do you start a comment in Python?
- B) # (Correct answer)
- A) //
- /*
- --
Correct answer: B) #
In Python, comments are started with the # symbol.
Question 5: Which of the following is a valid variable name in Python?
- variable_ name (Correct answer)
- 2ndVariable
- variable-name
- variable name
Correct answer: variable_ name
Variable names in Python must start with a letter or underscore and cannot contain spaces or hyphens.
Question 6: What is the output of the following code?
- print(2 ** 3)
- 6
- 8 (Correct answer)
- 23
- 9
Correct answer: 8
The ** operator in Python is used for exponentiation. 2 ** 3 equals 8.
Question 7: Which of the following is used to define a function in Python?
- function
- def (Correct answer)
- func
- define
Correct answer: def
The def keyword is used to define a function in Python.
Question 8: What will be the output of the following code?
- HelloWorld
- Hello World (Correct answer)
- Hello + World
- HelloWorld
Correct answer: Hello World
The + operator concatenates strings in Python, and adding " " between x and y results in "Hello World".
Question 9: Which of the following statements will correctly check if a variable a is equal to 10?
- if a == 10: (Correct answer)
- if a = 10:
- if (a == 10)
- if a === 10:
Correct answer: if a == 10:
The == operator is used to check equality, and the correct syntax for an if statement in Python ends with a colon.
Question 10: How do you create a list in Python?
- list = [1, 2, 3] (Correct answer)
- list = (1, 2, 3)
- list = {1, 2, 3}
- list = <1, 2, 3>
Correct answer: list = [1, 2, 3]
Lists in Python are created using square brackets, with elements separated by commas.
Question 11: What does the following code print?
- 123
- 12 (Correct answer)
- 123
- 1234
Correct answer: 12
The range(3) function generates numbers from 0 to 2, and the for loop prints each number in this range.
What is the correct file extension for Python files?