Must-Know Questions & Answers
Identify which of the following is an interpreted language.
Pascal, C and C++ are all compiled languages. Python is an interpreted language — the official implementation uses byte code interpretation.
Python syntax is case-sensitive. State true or false.
Case sensitivity means that 'x' is different from 'X', and 'John' is different from 'john'. Python syntax is case-sensitive.
Select the command to be used to run the Python script file named t.py.
To run Python files from the command prompt, set the path of Python and run the file using: python filename.py
Select the method that can be used to create a directory in Python.
Python's OS module provides os.mkdir(path) to create a directory. It creates a directory at the specified path.
Name the creator of Python.
Guido van Rossum is the creator of Python. Python was conceived in the late 1980s and its implementation was started in December 1989.
In Python, who detects the syntax error and when?
Syntax errors arise when the Python parser is unable to understand a line of code. They are reported by the interpreter at runtime.
Identify the symbol that a Python single-line comment begins with.
Single-line comments in Python begin with the hash (#) character and are automatically terminated by the end of that line.
Identify the style that Python paragraph (multi-line) comments use.
For writing Python paragraph comments, you may use triple-quoted strings (''' or """). Add the triple-quoted string at the beginning and end of the comment block.
Select the command to be used to start Python from the command prompt.
The command 'python' must be used to start the Python interactive interpreter from the command prompt.
Select the correct code snippet: A: print("Programming is fun") print("Python is fun") [extra indentation on second line] B: print("Programming is fun") print("Python is fun") C: print("Programming is fun) print("Python is fun") D: print("Programming is fun") print("Python is fun)
Option A has wrong indentation (Python is sensitive to indentation). Options C and D have missing closing quotation marks. Option B is syntactically correct.
Define what kind of language Python is.
Interpreted/compiled is a property of the implementation, not the language itself. The official Python implementation uses byte code interpretation, so Python is called an interpreted language.
Object Oriented Programming is possible in Python. State whether True or False.
OOP is a paradigm where logic is coded in terms of Classes and Objects. Python supports OOP, as well as Procedural and Functional programming styles.
Identify the correct operator for exponentiation (x to the power y).
The ** operator in Python raises the number on the left to the power of the exponent on the right. E.g., 5**3 = 125. Note: pow(x,y) also works but x**y is the operator form.
Identify which one of these is the floor division operator in Python.
In Python 3, the / operator returns the quotient with decimals, while the floor division operator // returns the quotient after truncating the decimal portion.
Mathematical operations can be performed on a string. State whether True or False.
Mathematical operations (such as addition, subtraction, multiplication of values) cannot be performed on strings. Attempting to do so raises a TypeError.
Analyse and find which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100: A: for i in range(1, 99): sum += i / (i + 1) B: for i in range(1, 100): sum += i / (i + 1) C: for i in range(1.0, 99.0): sum += i / (i + 1) D: for i in range(1.0, 100.0): sum += i / (i + 1)
Python range() does not support float type, so C and D are invalid. Option A is wrong because i goes from 1 to 98 (last fraction is 98/99, not 99/100). Only Option B is correct.
Which single line of code can replace this block? nums = [1,2,3,4,5,6,7,8,9] x = 0 for n in nums: x = x + n print(x)
The code computes the sum of 1 through 9. range(1, 10) generates 1 to 9 inclusive. print(sum(range(1,10))) is the correct one-liner.
Select the choice that should NOT appear in the place of EXP in: for k in EXP:
Lists, dictionaries, strings, and integer ranges are all valid iterables in a for loop. However, Python's range() does not accept floats, so a range of float is illegal.
Which statement best describes the behavior of: x != 0 and y % x != 0
Due to short-circuit evaluation, if x == 0, the first condition (x != 0) is False and the second part (y % x) is never evaluated, preventing ZeroDivisionError. The expression is valid for all values of x.
Analyse and predict the output: isCorrect = False print("Correct" if isCorrect else "Incorrect")
The ternary expression prints "Correct" only if isCorrect is True. Since isCorrect is False, the output is "Incorrect".
Based on our question bank analysis, master these concepts to score high in Python.
"Focus on understanding the logic behind pseudocode loops and selection statements, as they form the bulk of technical assessments."