Test your mastery of foundational Python concepts such as printing, comments, indentation, variable rules, and basic input/output. Each question is designed to assess your awareness of fine syntax details and language behavior.
Print Statement Behavior
When executing print('Hello', 'World', sep='*', end='?'), what is the exact output produced?
- Hello*World
- Hello* World?
- HelloWorld?
- Hello World?
- Hello*World?
Comment Syntax Correctness
Which of the following lines will not result in a syntax error if inserted in a Python script?
- # This is a comment
- -- This is a comment
- u003C!-- This is a comment --u003E
- ** This is a comment
- // This is a comment
Indentation Impact
Given this code snippet, what happens?nnx = 3n if x u003E 2:n print('Hi')
- IndentationError is raised
- It prints 'Hi' with no errors
- NameError: name 'print' is not defined
- TypeError: 'int' object is not callable
- SyntaxError: unexpected EOF while parsing
Variable Name Validity
Which variable name below is not valid in Python?
- my_var2
- my-var
- MyVar
- _myVar
- var_3
Type Preservation After Input
What is the type of variable 'x' after executing x = input('Enter something: ')?
- list
- str
- float
- bool
- int
Accurate Commenting Out of Multiple Lines
Which is the most Pythonic way to comment out several lines of code?
- Surround with // and //
- Begin each line with --
- Begin each line with #
- Surround with u003Cu003C and u003Eu003E
- Surround with /* and */
String Concatenation Output
What is printed by print('py' + str(3*2))?
- py*6
- py 6
- py32
- py3*2
- py6
Using Escape Characters
Given print('Line1
Line2'), what is the output?
- Line1 Line2
- Line1
Line2
- Line1nLine2
- Line1/Line2
- Line1nLine2
Determining Data Types
What value does type(12.0) return?
- 'float'
- u003Cclass 'float'u003E
- float
- u003Ctype 'float'u003E
- u003Cclass 'int'u003E
Multiple Assignment Nuances
If you write a, b = 1, 2 in Python, what are the values of a and b afterwards?
- a = [1, 2], b = None
- a = '1', b = '2'
- a = None, b = [1, 2]
- a = 1, b = 2
- a = 2, b = 1
Printing Without Newline
Which print statement suppresses the automatic newline at the end?
- print('Done', stop='')
- print('Done', newline='')
- print('Done', end='')
- print('Done', finish='')
- print('Done', noline='')
Variable Reassignment
What is the value of y after executing: y = 7; y = y + 2; y = str(y)?
- 7
- '7'
- TypeError is raised
- 9
- '9'
Illegal Expression Use
Which of the following will produce a SyntaxError if entered as a statement?
- x = True
- x = 1_000_000
- 3x = 9
- x = 3 // 2
- x, y = 1, 2
Input Processing and Casting
If the user enters '25' when prompted by age = input('Age: '); age = int(age), what is the value and type of 'age'?
- '25', int
- '25', str
- 25, str
- 25, int
- SyntaxError
Indentation in Nested Structures
What will be the result of this code block?nx = 2nif x u003E 1:n if x u003E 0:n print('A')n print('B')nprint('C')
- A B
- A B C
- C B A
- A C B
- B A C
Variable Initialization Rules
What happens if you reference a variable in Python before assigning it a value, such as with print(z)?
- It prints 'z'
- NameError is raised
- AttributeError is raised
- It prints 0
- It prints nothing