Exit Chapter 03 · 🧱 Python Fundamentals — Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 57 0 correct so far

🧱 Python Fundamentals Quiz

Q1.

The set of valid characters that Python recognises is called its:

Explanation

Python's character set includes letters, digits, special symbols, whitespaces and Unicode characters.

Q2.

Which of these is NOT part of Python's character set?

Explanation

Python supports letters, digits, symbols, whitespace and all Unicode characters, not just one language.

Q3.

The smallest individual unit of a Python program is called a:

Explanation

A token is the smallest unit of a program, like a word in a sentence.

Q4.

How many types of tokens are there in Python?

Explanation

Keywords, Identifiers, Literals, Operators and Punctuators — KILOP.

Q5.

Which of these is NOT a type of token?

Explanation

Comments are ignored by Python and are not tokens.

Q6.

Reserved words that have a special meaning in Python are called:

Explanation

Keywords like if, for and while are reserved and cannot be used as names.

Q7.

How many keywords are there in Python 3 (as listed in the notes)?

Explanation

Python 3 has 35 keywords; you can see them with keyword.kwlist.

Q8.

Which keywords start with a capital letter?

Explanation

Only True, False and None begin with a capital letter.

Q9.

Which of these is a Python keyword?

Explanation

while is a keyword; print and input are built-in function names, not keywords.

Q10.

A name given to a variable, function or other object is called a(n):

Explanation

Identifiers are names chosen by the programmer, such as marks or total.

Q11.

Which of these is a VALID identifier?

Explanation

Identifiers can use letters, digits and underscore, cannot start with a digit, have no spaces and cannot be keywords.

Q12.

Which of these is an INVALID identifier?

Explanation

A hyphen (-) is not allowed in an identifier; use an underscore instead.

Q13.

Why is 1st_name an invalid identifier?

Explanation

An identifier cannot begin with a digit.

Q14.

Why is 'class' an invalid identifier?

Explanation

Keywords cannot be used as identifiers.

Q15.

Are Name and name the same identifier in Python?

Explanation

Python treats uppercase and lowercase letters as different.

Q16.

Fixed values written directly in a program, like 25 or "Hello", are called:

Explanation

Literals are constant values used directly in the code.

Q17.

"Delhi" is which type of literal?

Explanation

Text in quotes is a string literal.

Q18.

3.14 is which type of literal?

Explanation

A number with a decimal point is a float literal.

Q19.

Which of these is a Boolean literal?

Explanation

True and False are the two Boolean literals; "True" in quotes is a string.

Q20.

None is which type of literal?

Explanation

None is Python's special literal that means 'no value'.

Q21.

3 + 4j is a literal of which type?

Explanation

Numbers with a j part are complex numbers.

Q22.

Symbols that perform operations on values, like + and *, are called:

Explanation

Operators act on values; the values are called operands.

Q23.

In the expression a + b, a and b are called:

Explanation

The values an operator works on are called operands.

Q24.

Symbols like ( ) [ ] { } , : that organise code are called:

Explanation

Punctuators (separators) give structure to statements.

Q25.

Which symbol is used for a single-line comment in Python?

Explanation

Everything after # on that line is a comment.

Q26.

What does Python use to write a comment spread over many lines?

Explanation

A multi-line comment can be written with # on each line or inside triple quotes.

Q27.

Indentation in Python is used to:

Explanation

Indentation is compulsory in Python and marks a block of code.

Q28.

What error is shown when a statement is wrongly indented?

Explanation

Wrong or unexpected spaces at the beginning of a line give IndentationError.

Q29.

How many spaces are usually used for one level of indentation?

Explanation

The standard convention is 4 spaces per indentation level.

Q30.

A named memory location whose value can change is called a:

Explanation

A variable is a name that refers to a value stored in memory.

Q31.

In the statement total = a + b, which part is the l-value?

Explanation

The l-value is on the left of = and receives the value.

Q32.

In the statement total = a + b, which part is the r-value?

Explanation

The r-value is the expression on the right of = whose value is assigned.

Q33.

Which statement is INVALID because a literal cannot be an l-value?

Explanation

Only a name can be on the left of =; 10 = x gives a SyntaxError.

Q34.

What is the output of:

a = b = 5
print(a, b)
Explanation

a = b = 5 gives the same value 5 to both variables.

Q35.

What is the output of:

x, y = 3, 7
print(x, y)
Explanation

Values are assigned in order: x gets 3 and y gets 7.

Q36.

What is the output of:

a, b = 10, 20
a, b = b, a
print(a, b)
Explanation

a, b = b, a swaps the two values.

Q37.

What is the output of:

x = 5
x = "five"
print(type(x))
Explanation

Python is dynamically typed; x now holds a string.

Q38.

Which function shows the data type of a value?

Explanation

type(25) gives <class 'int'>.

Q39.

What does the input() function ALWAYS return?

Explanation

input() returns whatever the user types as a string.

Q40.

A user types 5 for a = input(). What is the output of print(a * 2)?

Explanation

a is the string '5', and '5' * 2 repeats it.

Q41.

Which statement correctly reads a whole number from the user?

Explanation

input() reads a string, and int() converts it into an integer.

Q42.

A user types 12 for x = input(). What does print(x + 3) give?

Explanation

x is the string '12'; a string and an int cannot be added.

Q43.

What is the output of:

print(int("25") + 5)
Explanation

int("25") converts the string to the number 25.

Q44.

Which function converts the input "7.5" into a number?

Explanation

float("7.5") gives 7.5; int("7.5") would give a ValueError.

Q45.

What does int("7.5") give?

Explanation

int() cannot convert a string containing a decimal point.

Q46.

What is the default value of the sep argument in print()?

Explanation

print() separates items with a space unless sep is changed.

Q47.

What is the default value of the end argument in print()?

Explanation

By default print() ends by moving to a new line.

Q48.

What is the output of:

print("A", "B", "C", sep="-")
Explanation

sep="-" puts - between the items.

Q49.

What is the output of:

print("Hi", end=" ")
print("there")
Explanation

end=" " ends the first print with a space instead of a newline.

Q50.

What is the output of:

print(10, 20, sep="")
Explanation

An empty sep joins the items with nothing between them.

Q51.

What is the output of:

print("Sum =", 4 + 6)
Explanation

4 + 6 is calculated, and print adds a space between items.

Q52.

Which statement has an ERROR?

Explanation

Items in print() must be separated by commas.

Q53.

What is the output of:

r = 2
area = 3.14 * r * r
print(area)
Explanation

3.14 × 2 × 2 = 12.56; a float in the calculation gives a float result.

Q54.

What is the output of:

x = 10
x = x + 5
print(x)
Explanation

x + 5 is calculated using the old value 10 and stored back in x.

Q55.

What error does this code give?

print(score)
score = 90
Explanation

A variable must be given a value before it is used.

Q56.

In Python, what happens when you assign a new value to an existing variable?

Explanation

A variable name simply starts referring to the new value.

Q57.

Which of these is a valid multiple assignment?

Explanation

The number of names must match the number of values.