Test your Python fundamentals with our comprehensive collection of multiple-choice questions on basic concepts. Perfect for beginners to practice and reinforce their learning.
Python
What is Python?
A) A type of snake
B) A high-level programming language
C) A web browser
D) An operating system
Answer: B) A high-level programming language
Which of the following is a popular Integrated Development Environment (IDE) for Python?
A) Visual Studio Code
B) Microsoft Word
C) Adobe Photoshop
D) Google Chrome
Answer: A) Visual Studio Code
Which tool is used for managing and installing Python packages? [Python Quiz #53]
A) pip
B) npm
C) yarn
D) gem
Answer: A) pip
What does IDE stand for in the context of Python programming?
A) Integrated Development Environment
B) Integrated Data Environment
C) Internal Development Engine
D) Internet Development Environment
Answer: A) Integrated Development Environment
What is the purpose of virtual environments in Python?
A) To provide a web-based interface for Python development
B) To create isolated environments for different Python projects
C) To compile Python code into machine code
D) To improve the speed of Python code execution
Answer: B) To create isolated environments for different Python projects
Which tool is used for version control in Python projects?
A) Git
B) Docker
C) Kubernetes
D) Jenkins
Answer: A) Git
Which of the following is the correct extension of the Python file? [Python Quiz #51]
A) .python
B) .pl
C) .p
D) .py
What is Jupyter Notebook primarily used for in the Python ecosystem? [Python Quiz #54]
A) Web development
B) Writing and sharing code, visualizations, and text
C) Game development
D) Mobile app development
Answer: B) Writing and sharing code, visualizations, and text
Who created Python and in which year? [1]
A) James Gosling in 1995
B) Guido van Rossum in 1991
C) Bjarne Stroustrup in 1983
D) Dennis Ritchie in 1972
Answer: B) Guido van Rossum in 1991
Which of the following features is a key characteristic of Python? [Python Quiz #52]
A) Statically typed
B) Compiled language
C) Interpreted language
D) Requires manual memory management
What is the purpose of the virtual environment tool in Python?
A) To create virtual machines
B) To manage and isolate project-specific dependencies
C) To design virtual reality experiences
D) To develop mobile applications
Answer: B) To manage and isolate project-specific dependencies
What is the Python Package Index (PyPI)?
A) A text editor for Python
B) A library for machine learning
C) A repository of software for the Python programming language
D) An IDE for Python development
Answer: C) A repository of software for the Python programming language
What is pip in Python?
A) A text editor
B) A package installer
C) A version control system
D) A web framework
Answer: B) A package installer
Which tool is commonly used for creating virtual environments in Python?
A) npm
B) pip
C) venv
D) docker
Answer: C) venv
Which Integrated Development Environment (IDE) is specifically designed for Python development? [Python Quiz #54]
A) Visual Studio
B) IntelliJ IDEA
C) PyCharm
D) Eclipse
Answer: C) PyCharm
Which of the following is true about Python?
A) Python is a compiled language
B) Python is a low-level programming language
C) Python supports object-oriented programming
D) Python does not support modules
Answer: C) Python supports object-oriented programming
Which of the following is NOT a feature of Python?
A) Interpreted language
B) Compiled language
C) High-level language
D) Object-oriented language
Answer: B) Compiled language
print function
[video:Can You Guess the Output of this Python Code?
Which of the following is the correct syntax for the print statement in Python?
A) print (“text”)
B) println (“text”)
C) echo (“text”)
D) None
What will be the output of the following code?
print("Hello, world!")
A) Hello
B) world
C) Hello, world!
D) There will be no output.
How can you print multiple values on a single line in Python?
Use commas to separate the values within the print statement.
Use semicolons to separate the values within the print statement.
Use the + operator to concatenate the values before printing.
Create a list of the values and print the list.
Which of the following statements will print the value of the variable x?
print(x)
print “x”
println(x)
echo x
What is the purpose of the sep argument in the print function?
To specify the separator between multiple values printed on the same line.
To specify the end character for the printed line.
To specify the file to which the output should be printed.
To specify the format of the output.
What is the purpose of the end argument in the print function?
To specify the separator between multiple values printed on the same line.
To specify the end character for the printed line.
To specify the file to which the output should be printed.
To specify the format of the output.
How can you print a string without a newline character?
print(string, end=””)
print(string, sep=””)
print(string + “”)
print(string; “”)
What is the output of the following code? [Python Quiz #75]
name="Alice"age=30print("My name is",name,"and I am",age,"years old.")
A) My name is Alice and I am 30 years old.
B) My name is Aliceand I am 30years old. (No separation)
C) Alice 30 (Values printed without labels)
D) An error (Incorrect syntax)
How can you format a string in Python to insert variables directly within it?
a) Using string concatenation with the + operator (Limited control)
b) Using the format method (Less readable for complex formatting)
c) Using f-strings
d) All of the above (f-strings are generally preferred)
Which of the following statements is NOT valid for the print function in Python?
a) print(“Hello, world!”)
b) print(5 + 3) (prints the result of the expression)
c) print() (prints an empty line)
d) print(x, y, sep=”,”) (prints x and y with a comma separator)
How can you prevent a newline character from being printed at the end of the output in Python?
a) By using a semicolon at the end of the print statement (this is not valid Python syntax)
b) Using the end argument within the print function and setting it to an empty string (“”)
c) Specifying a special flag in the function call
d) There’s no way to suppress the newline character
What is a syntax error in Python?
A) An error caused by incorrect logic in the code.
B) An error detected when the code violates the rules of the Python language.
C) An error that occurs during runtime.
D) An error caused by a variable not being defined.
Identify the error in the following code snippet:
prin("Hello World!")
A) Incorrect variable name
B) Missing colon
C) Misspelled keyword
D) Missing parenthesis
Hint NameError: name ‘prin’ is not defined.
What should be done to correct the syntax error in the following code?
print("Hello World!"
A) Add a closing quotation mark.
B) Add a closing parenthesis.
C) Add a colon at the end.
D) Indent the line correctly.
Comments:
What is the primary purpose of comments in Python code?
To execute instructions for the computer
To temporarily disable lines of code
To make the code more readable and understandable for humans
To create errors for debugging
Which of the following is the correct syntax for a single-line comment in Python?
// This is a comment
/* This is a comment */
# This is a comment
{ This is a comment }
How can you create a multi-line comment in Python?
Using triple single quotes (‘’’)
Using triple double quotes (“””)
Using backslash () at the end of each line
Using the comment keyword
What happens when you run code that includes comments?
The comments are executed along with the code.
The comments are ignored by the Python interpreter.
The comments are displayed as output.
The comments are converted into machine code.
Indentation:
What is the purpose of indentation in Python?
To define code blocks
To define functions
To define variables
To print output
Answer: a) To define code blocks
Which of the following is a correct way to indent code in Python?
a) Using tabs
b) Using spaces
c) Using both tabs and spaces
d) Using neither tabs nor spaces
Answer: b) Using spaces (Python recommends using 4 spaces for indentation)
What happens if you don’t indent your code in Python?
a) It will run correctly
b) It will throw a syntax error
c) It will print an error message
d) It will ignore the code
Answer: b) In Python, improper indentation specifically results in an IndentationError. While a syntax error is a broad category for any error in the syntax, an IndentationError is a specific type of syntax error related to incorrect indentation.
What is the indentation error in the following code?
if True:
print("True")
print("False")
a) Missing indentation
b) Extra indentation
c) Incorrect indentation
d) No error
Answer: b) Extra indentation (the second print statement has extra indentation)
What is the standard number of spaces used for indentation in Python?
a) 2 spaces
b) 4 spaces
c) 6 spaces
d) 8 spaces
Answer: b) 4 spaces
Which of the following code snippets is correctly indented?
a)
```python
if True:
print("True")
print("False")
b)
ifTrue:print("True")print("False")
c)
ifTrue:print("True")print("False")
d)
ifTrue:print("True")print("False")
Answer: b)
ifTrue:print("True")print("False")
In Python, indentation is used to define ____ in the code.