Explore key Python topics often encountered in interviews with these easy multiple-choice questions. Great for beginners or those preparing for Python fundamentals.
What is the standard file extension for Python files?
Explanation: The correct extension for Python files is .py. The options .pt and .python are incorrect and not recognized by Python interpreters. .txt is a generic text file format, not specific to Python.
Which function is commonly used in Python to display output to the screen?
Explanation: The print() function is used to display output in Python. echo() is used in some other languages, not Python. display() and output() are not standard Python functions for showing output.
How do you write a single-line comment in Python?
Explanation: Single-line comments in Python start with #. The // and /* */ styles are used in languages like JavaScript or C. <!-- --> is used in HTML and not for Python comments.
In Python, what is indentation used for?
Explanation: Indentation in Python determines code blocks, especially for functions and control structures. It is not about styling, declaring variables, or skipping lines, which are incorrect or unrelated uses.
Which one is a numeric data type in Python?
Explanation: int stands for integer and is a numeric data type. str is for strings, list is for collections, and bool is for Boolean values, not numbers.
Which of these is a valid way to assign a value to a variable in Python?
Explanation: x = 5 assigns the integer 5 to variable x in Python. let and int as prefixes are not used in Python. x: 5 is incorrect syntax for variable assignment in Python.
Which operator is used to join two strings in Python?
Explanation: The + operator joins two strings. -, *, and & do not perform string concatenation in Python.
Which symbol is used to create a list in Python?
Explanation: Lists in Python are created using square brackets [ ]. Curly braces { } are for dictionaries or sets, parentheses ( ) are for tuples, and < > are not used for data structures.
Which keyword is used to define a function in Python?
Explanation: The correct keyword to define a function in Python is def. func, function, and define are not valid Python keywords for creating functions.
Which loop is commonly used to iterate over items in a list in Python?
Explanation: The for loop is standard in Python for iterating through a list. do while and repeat do not exist in Python, and foreach is not a Python keyword.