Python Fundamentals - Syntax, Data Types,
Operators and Strings — Questions & Answers
1. What is Python?
A. A high-level, interpreted, general-purpose programming language
B. A compiled low-level language
C. A database
D. An operating system
Answer: A. A high-level, interpreted, general-purpose programming language
Rationale: Created by Guido van Rossum.
2. Why is Python popular for IT automation?
A. It only runs on Windows
B. It requires no interpreter
C. Readable syntax, a large standard library and many third-party packages
D. It's a hardware language
Answer: C. Readable syntax, a large standard library and many third-party
packages
Rationale: Batteries included.
3. What is the current major version of Python in use?
A. Python 3
B. Python 2
C. Python 1
D. Python 4
Answer: A. Python 3
Rationale: Python 2 reached end of life in 2020.
4. How does Python define code blocks?
A. Curly braces
B. Semicolons
C. Indentation
D. Keywords BEGIN and END
Answer: C. Indentation
Rationale: Whitespace matters.
,5. How many spaces does PEP 8 recommend per indentation level?
A. 2
B. 8
C. 4
D. 1
Answer: C. 4
Rationale: Style guide.
6. What is PEP 8?
A. Python's official style guide
B. A Python version
C. A package manager
D. A testing tool
Answer: A. Python's official style guide
Rationale: Readability.
7. Which symbol starts a single-line comment in Python?
A. //
B. --
C. /*
D. #
Answer: D. #
Rationale: Comments.
8. What is a docstring?
A. A string literal at the start of a module, function or class describing it
B. A comment with #
C. A variable
D. An error message
Answer: A. A string literal at the start of a module, function or class describing
it
Rationale: Documentation.
9. What function displays output to the console?
A. input()
B. echo()
C. print()
D. display()
Answer: C. print()
Rationale: Output.
, 10. What function reads user input from the keyboard?
A. print()
B. read()
C. input()
D. scan()
Answer: C. input()
Rationale: Returns a string.
11. What data type does input() return?
A. int
B. float
C. bool
D. str
Answer: D. str
Rationale: Always a string.
12. What is a variable in Python?
A. A fixed constant only
B. A function
C. A name that refers to a value stored in memory
D. A module
Answer: C. A name that refers to a value stored in memory
Rationale: Assignment.
13. Which is a valid Python variable name?
A. 2servers
B. server_count
C. server-count
D. class
Answer: B. server_count
Rationale: Rules.
14. Why is "class" not a valid variable name?
A. It's too short
B. It contains no digits
C. It's uppercase
D. It's a reserved keyword
Answer: D. It's a reserved keyword
Rationale: Keywords.
15. What naming convention does PEP 8 recommend for variables and functions?
A. snake_case
B. camelCase
C. PascalCase
D. UPPERCASE
Answer: A. snake_case
Rationale: Style.