pythonbeginner
Python Basics Quiz
Test your understanding of Python fundamentals: syntax, types, control flow, and built-in functions.
7 questions
By EZ4Code Team
1. Which of the following is the correct way to create a variable in Python?
# Option A
name = "Alice"
# Option B
let name = "Alice"
# Option C
var name = "Alice"
# Option D
string name = "Alice"name = "Alice"
let name = "Alice"
var name = "Alice"
string name = "Alice"
Explanation: Python is dynamically typed, so you assign a value directly with `name = "Alice"` — no `let`, `var`, or type declaration needed. `let`/`var` are JavaScript keywords, and `string name` is C#/Java syntax.
2. What is the output of the following code?
print(type(3.14))<class 'float'>
<class 'int'>
<class 'double'>
<class 'number'>
Explanation: Python calls decimal numbers `float` (not `double` like Java/C). `3.14` is a float literal. There is no `number` type in Python — integers use `int` and decimals use `float`.
3. How do you start a comment in Python?
//
#
/*
--
Explanation: Python uses `#` for single-line comments. `//` is JavaScript/Java/C, `/* */` is block comment syntax in those languages, and `--` is SQL/Lua.
4. What does the `len()` function return for the string `"hello"`?
print(len("hello"))4
5
6
Error
Explanation: `len()` returns the number of characters. `"hello"` has 5 characters (h-e-l-l-o). Python strings are 0-indexed but `len()` counts total characters, not the last index.
5. Which collection type does NOT allow duplicate values?
list
tuple
set
dict (keys can duplicate)
Explanation: A `set` automatically removes duplicates — it stores only unique values. Lists and tuples allow duplicates. Dictionary keys must be unique (so duplicates are silently overwritten), but the question asks which type does not ALLOW duplicates — sets enforce uniqueness by design.
6. What will this code print?
for i in range(3):
print(i, end=" ")1 2 3
0 1 2
0 1 2 3
1 2
Explanation: `range(3)` produces 0, 1, 2 (start at 0, stop BEFORE 3). The `end=" "` replaces the default newline with a space, so output is `0 1 2 `.
7. Which keyword is used to define a function in Python?
function
def
func
fn
Explanation: Python uses `def` to define functions, e.g. `def greet(name):`. `function` is JavaScript, `fn` is Rust, and `func` is Swift/Go.
More python Quizzes
Python Intermediate Quiz
intermediateList comprehensions, decorators, generators, exception handling, and OOP in Python.
Python Object-Oriented Programming
intermediateClasses, inheritance, polymorphism, magic methods and properties
Python Data Science
advancedpandas, numpy, matplotlib basics
Python Asynchronous Programming
advancedasyncio, coroutines, tasks
Python Decorators
intermediateDecorators, closures and higher-order functions