Exit Chapter 05 · 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.

What is a character set in Python?

Explanation

A character set is the set of valid characters a language recognises; a character is the smallest unit of a program.

Q2.

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

Explanation

Python's character set has letters (A–Z, a–z), digits (0–9), special symbols and whitespaces.

Q3.

Which of the following are whitespace characters?

Explanation

Whitespaces are characters that create space in code: blank space, tab, newline and carriage return.

Q4.

What is a token in Python?

Explanation

A token (lexical unit) is the smallest individual unit in a Python program; the interpreter breaks each line into tokens.

Q5.

Which list correctly gives the five types of Python tokens?

Explanation

Python tokens are keywords, identifiers, literals, operators and punctuators.

Q6.

What are keywords in Python?

Explanation

Keywords are reserved words with special meaning; they cannot be used as identifiers.

Q7.

How many keywords does Python 3 have (as per the notes)?

Explanation

Python 3 has 35 keywords.

Q8.

Which Python keywords begin with a capital letter?

Explanation

All keywords are lowercase except True, False and None.

Q9.

Which of the following is a keyword?

Explanation

elif is a keyword. print, input and len are built-in functions, not keywords.

Q10.

A student says 'print is a keyword'. What is the correct understanding?

Explanation

print, input, len and range are built-in functions, not keywords (though they should not be used as variable names).

Q11.

What is an identifier?

Explanation

An identifier is the name given to program entities like variables, functions, classes and modules.

Q12.

Which of the following is a valid identifier?

Explanation

_fruit starts with an underscore and has only letters. 2fruit starts with a digit, for is a keyword, and fruit#1 contains a special symbol.

Q13.

Why is 1name an invalid identifier?

Explanation

An identifier cannot start with a digit.

Q14.

Why is 'my name' an invalid identifier?

Explanation

Identifiers cannot contain spaces.

Q15.

Which identifier is invalid because it contains a special symbol?

Explanation

na@me contains the @ symbol, which is not allowed in an identifier.

Q16.

Why is 'class' not allowed as a variable name?

Explanation

class is a keyword, and keywords cannot be used as identifiers.

Q17.

Which statement about identifiers is correct?

Explanation

Identifiers can be of any length and are case-sensitive (age and Age are different).

Q18.

Which set contains ONLY valid identifiers?

Explanation

age, _name and student1 all start with a letter or underscore and contain only letters/digits/underscores. 1st starts with a digit, 'total marks' has a space, and if is a keyword.

Q19.

What is a literal?

Explanation

A literal is a raw data value written directly in the code, such as 10, 3.14 or 'Hello'.

Q20.

Which of these is a complex number literal?

Explanation

Numeric literals include integers (10), floats (3.14) and complex numbers (3+5j).

Q21.

Which are the Boolean literals in Python?

Explanation

Boolean literals have a capital first letter: True and False.

Q22.

Which special literal represents the absence of a value?

Explanation

None is Python's special literal representing the absence of a value.

Q23.

Which quotes can be used to write a multi-line string literal?

Explanation

Triple quotes ('''...''') allow multi-line strings; single or double quotes are used for ordinary strings.

Q24.

Which prefix marks a binary integer literal?

Explanation

Binary literals use 0b or 0B, octal uses 0o or 0O, and hexadecimal uses 0x or 0X.

Q25.

What is the decimal value of the literal 0o17?

Explanation

0o17 is octal: 1×8 + 7 = 15.

Q26.

What is the decimal value of the literal 0x1A?

Explanation

0x1A is hexadecimal: 1×16 + 10 = 26.

Q27.

What is the decimal value of the literal 0b1010?

Explanation

0b1010 is binary: 8 + 2 = 10.

Q28.

How does Python treat a single character such as 'A'?

Explanation

Python has no separate character type; 'A' is a string of length 1.

Q29.

The values that an operator acts on are called:

Explanation

Operators carry out computations on values called operands.

Q30.

Which group of operators compares two values?

Explanation

Relational operators (==, !=, >, <, >=, <=) compare two values.

Q31.

The operators 'in' and 'not in' belong to which category?

Explanation

in and not in are membership operators that test membership in a sequence.

Q32.

The operators 'is' and 'is not' belong to which category?

Explanation

is and is not are identity operators that compare memory identity.

Q33.

Which of these is a logical operator?

Explanation

and, or and not are the logical operators.

Q34.

What is the result of 7 // 2 in Python?

Explanation

// is floor division and gives the floor (integer part): 3.

Q35.

What is the main role of punctuators?

Explanation

Punctuators organise program structure (grouping, separating, terminating), e.g. ( ) [ ] { } , : .

Q36.

How does Python define blocks of code?

Explanation

Python uses indentation instead of { }; it is mandatory and must be consistent.

Q37.

Mixing tabs and spaces inconsistently for indentation causes:

Explanation

Inconsistent indentation causes an IndentationError; use 4 spaces per level consistently.

Q38.

Which symbol starts a single-line comment in Python?

Explanation

Single-line comments start with #; multi-line comments/docstrings use ''' ... '''.

Q39.

What is a variable in Python?

Explanation

A variable is a named memory location whose value can change during program execution.

Q40.

When is a variable created in Python?

Explanation

Python has no separate declaration statement; a variable is created when you assign a value to it.

Q41.

What does a = b = c = 10 do?

Explanation

Chained assignment gives the same value, 10, to all three variables.

Q42.

After a, b, c = 10, 20, 30, what is the value of b?

Explanation

Values are assigned in order: a = 10, b = 20, c = 30.

Q43.

Which statement swaps a and b without a third variable?

Explanation

a, b = b, a swaps the two values in one line.

Q44.

What does the id() function show?

Explanation

id() gives the unique identifier (memory address) of the object; type() gives its type.

Q45.

What does print(type(10)) display?

Explanation

type() shows the class of the value; 10 is an int.

Q46.

What will type(True) return?

Explanation

True is a Boolean literal, so its type is bool.

Q47.

Python is 'dynamically typed'. This means:

Explanation

In a dynamically typed language, the type comes from the assigned value at runtime and can change when the variable is reassigned.

Q48.

After running x = 10, then x = "Hello", what is the type of x?

Explanation

Python is dynamically typed, so x now refers to the string "Hello".

Q49.

Why does "5" + 5 cause an error even though Python is dynamically typed?

Explanation

Dynamic typing does not mean 'no types'; Python will not mix str and int in +.

Q50.

What type of value does input() always return?

Explanation

input() always returns a string, even if the user types a number.

Q51.

Which statement correctly reads an integer age from the user?

Explanation

Wrap input() in int() to convert the string to an integer.

Q52.

What happens if you forget to type-cast input() before doing arithmetic with a number?

Explanation

input() returns a str; adding it to an int gives TypeError: unsupported operand type(s).

Q53.

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

Explanation

sep defaults to a single space; end defaults to a newline '\n'.

Q54.

What is the output of print("Hello", "World", sep="-", end="!\n")?

Explanation

sep='-' puts a dash between the items, and end='!\n' adds ! at the end: Hello-World!

Q55.

What is the output of this code?

a, b, c = 5, 10, 15 print(a, b, c, sep="*", end="#")

Explanation

The values are joined by * and the line ends with # instead of a newline: 51015#.

Q56.

What does this code print?

name = "Amit" marks = 95 print(f"{name} scored {marks} marks")

Explanation

In an f-string, the values of the variables in braces are placed into the text.

Q57.

In this code, what error does the first line contain?

1name = input(Enter name)

Explanation

1name is an invalid identifier because it starts with a digit, and the prompt text must be in quotes: name = input("Enter name").