Unlock hundreds more features
Save your Quiz to the Dashboard
View and Export Results
Use AI to Create Quizzes and Analyse Results

Sign inSign in with Facebook
Sign inSign in with Google

Take the Python Basics Knowledge Test

Test Your Core Python Programming Knowledge Here

Difficulty: Moderate
Questions: 20
Learning OutcomesStudy Material
Colorful paper art depicting a quiz on Python basics knowledge test

Ready to test your Python basics with a dynamic programming quiz? The Python Basics Knowledge Test features 15 multiple-choice questions to evaluate core skills and boost your confidence. It's ideal for beginners and educators seeking a quick assessment, and it can be freely modified in our editor. For deeper practice, check out the Python Variables Basics Quiz or the Python Fundamentals Quiz . Explore more quizzes to continue your learning journey.

What is the data type of the literal 3.14 in Python?
int
float
str
bool
The literal 3.14 includes a decimal point, making it a floating point number. In Python, such values have the type float.
Which of the following is a valid Python variable name?
1variable
variable-1
variable_1
variable 1
Variable names cannot start with a digit, contain hyphens, or include spaces. "variable_1" follows Python's naming rules.
Which operator is used for exponentiation in Python?
^
**
%
//
In Python, the "**" operator raises the left operand to the power of the right operand. Other symbols serve different operations.
What is the value of the expression 7 // 3 in Python?
2
2.333
1
3
The "//" operator performs integer (floor) division, discarding any remainder. Thus 7 // 3 equals 2.
Which of the following expressions is a boolean expression that evaluates to True?
5 > 3
5 < 3
"5" == 5
5 and 3
The comparison 5 > 3 returns True. "5" == 5 is False due to type mismatch, 5 < 3 is False, and 5 and 3 yields 3, not a boolean value.
Which list method adds an element 'x' to the end of a list L?
L.__add__('x')
L.append('x')
L.insert(len(L), 'x')
L.extend('x')
The append() method adds a single element to the end of a list. __add__ returns a new list, insert requires an index, and extend expects an iterable.
Which of the following is the correct syntax to import the built-in math module in Python?
import Math
import math
include math
from import math
Python is case-sensitive and uses the statement import math to load the math module. 'Math' would not match the module name.
What is the output of list(range(2, 10, 2))?
[2, 4, 6, 8]
[0, 2, 4, 6, 8]
[2, 10]
[2, 8]
range(2, 10, 2) generates values starting at 2 up to but not including 10 in steps of 2, producing [2, 4, 6, 8].
What is the output of the following code snippet? x = 5 def foo(): x = 3 print(x) foo() print(x)
3 then 5
5 then 3
3 then 3
5 then 5
Inside foo(), x is a local variable set to 3, so print(x) outputs 3. The global x remains 5, so the second print outputs 5.
Which function correctly opens a file named 'test.txt' for reading?
open('test.txt', 'w')
open('test.txt', 'r')
open('test.txt', 'rw')
file.open('test.txt','r')
The mode 'r' opens a file for reading. Mode 'w' opens for writing, 'rw' is invalid, and file.open is not a built-in call.
Which of the following is the correct way to catch all exceptions in Python?
try: ... except Exception:
try: ... catch Exception:
try: ... except:
try: ... handle Exception:
Using except Exception: will catch most built-in exceptions in a structured way. The other syntaxes are invalid in Python.
What is the difference between a list and a tuple in Python?
Lists are immutable and tuples are mutable
Lists are mutable and tuples are immutable
Both are mutable
Both are immutable
Lists can be changed after creation (mutable), whereas tuples cannot be modified once defined (immutable).
Which built-in function returns the number of items in a dictionary d?
len(d)
count(d)
size(d)
d.length()
The len() function returns the number of keys (items) in a dictionary. The other calls are not valid built-ins.
What is the result of this list comprehension: [i*i for i in range(3)]?
[0, 1, 4]
[1, 4, 9]
[0, 1, 2]
[1, 2, 3]
range(3) produces 0, 1, 2. Squaring each yields [0, 1, 4].
Consider the function definition: def add(a, b=2): return a + b What is the behavior of the parameter b?
b is a required positional parameter
b is a keyword-only parameter
b has a default value of 2
b cannot be changed
The parameter b is given a default value of 2. If no second argument is passed, b will be 2, but it can be overridden.
What will be the output of this code snippet? def func(a, L=[]): L.append(a) return L print(func(1)) print(func(2))
[1] [1, 2]
[1] [2]
[1, 2] [1, 2]
[1] [1]
The default list L is shared across calls. The second call appends to the same list created in the first call.
What is printed when this code is executed? def outer(): x = 5 def inner(): nonlocal x x = 3 inner() print(x) outer()
3
5
Error
None
The nonlocal statement allows inner() to modify the variable x in the enclosing scope, so x becomes 3 before printing.
What will the following function return? def f(): try: return 1 finally: return 2 print(f())
1
2
None
Error
In Python, a return in the finally block overrides the return in the try block, so f() returns 2.
In Python, what is the difference between the '==' operator and the 'is' operator?
'==' tests identity, 'is' tests equality
'==' tests equality, 'is' tests object identity
Both test equality
Both test identity
The '==' operator checks whether two objects have the same value, while 'is' checks whether they are the very same object in memory.
Given the dictionary d = {'x': 1, 'y': 2}, what does the dict comprehension {v: k for k, v in d.items()} produce?
{1: 'x', 2: 'y'}
{'x': 1, 'y': 2}
{1: 'y', 2: 'x'}
{'x': 'y', 'y': 'x'}
The comprehension iterates over key-value pairs and swaps them, producing a new dictionary where original values become keys and original keys become values.
0
{"name":"What is the data type of the literal 3.14 in Python?", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"What is the data type of the literal 3.14 in Python?, Which of the following is a valid Python variable name?, Which operator is used for exponentiation in Python?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}

Learning Outcomes

  1. Identify Python variables, data types, and operators
  2. Apply control flow constructs like loops and conditionals
  3. Demonstrate understanding of functions and modules
  4. Analyse list, tuple, and dictionary manipulation
  5. Master error handling and basic debugging techniques

Cheat Sheet

  1. Understanding Python Variables and Data Types - Get to know how to declare variables and identify data types like integers, floats, strings, and booleans in Python. For example, age = 25 sets an integer to the variable age, while name = "Alice" makes a string. Mastering these basics lays the foundation for all your coding adventures. Explore the Python docs
  2. Mastering Python Operators - Dive into arithmetic, comparison, logical, and assignment operators to perform calculations and make decisions. For instance, 5 + 3 yields 8, and == checks for equality while != checks for inequality. Understanding operators helps you build the logic that powers your programs. Explore the Python docs
  3. Implementing Control Flow with Conditionals - Learn to steer your program with if, elif, and else clauses based on given conditions. For example, if score >= 90: print("A") outputs "A" for top marks. Conditionals let your code make dynamic choices and adapt to different situations. Explore the Python docs
  4. Utilizing Loops for Repetitive Tasks - Automate repetition with for and while loops so you don't have to write the same lines over and over. For example, for i in range(5): print(i) prints numbers 0 through 4 in a flash. Loops are your go-to tool for processing lists, counting, and more. Explore the Python docs
  5. Defining and Calling Functions - Create reusable chunks of code using the def keyword to keep your projects organized. For instance, def greet(name): return "Hello " + name packages a greeting into one neat block. Functions save you time, reduce errors, and make your code modular. Explore the Python docs
  6. Exploring Modules and Importing Libraries - Tap into Python's vast standard library and third-party modules to supercharge your projects. For example, import math opens up functions like math.sqrt() for quick calculations. Modules help you avoid reinventing the wheel and keep code clean. Explore the Python docs
  7. Manipulating Lists, Tuples, and Dictionaries - Master Python's core data structures for storing and organizing information. For instance, my_list.append(10) adds an element to a list, and my_dict['key'] = 'value' creates a dictionary entry. These versatile structures are the backbone of most Python programs. Explore the Python docs
  8. Handling Exceptions and Errors - Keep your programs running smoothly by catching errors with try and except blocks. For example, you can gracefully handle division-by-zero without crashing your script. Robust error handling makes your code more user-friendly and reliable. Explore the Python docs
  9. Debugging Techniques - Hunt down bugs using print statements or Python's built-in debugger (pdb) to step through your code. By inspecting variables and flow, you'll quickly pinpoint issues. Strong debugging skills are essential for building rock-solid applications. Explore the Python docs
  10. Writing Clean and Readable Code - Follow best practices like the PEP 8 style guide for consistent formatting and meaningful names. Clear code is easier to share, review, and maintain, especially on team projects. Polished code boosts productivity and collaboration. Explore the Python docs
Powered by: Quiz Maker