Challenge your understanding of Python basic fundamentals with these easy, concise questions. This quiz covers key Python concepts like data types, syntax, variables, and control flow, designed for beginners to strengthen their core programming skills.
Which of the following is the correct way to assign the value 10 to a variable named 'num' in Python?
Explanation: In Python, the correct way to assign a value is using a single equals sign as in num = 10. 'int num = 10' is a syntax used in other programming languages, but not in Python. 'num == 10' is a comparison, not an assignment. 'num: 10' does not assign a value; it is incorrect in this context.
If you execute the Python statement name = 'Alice', what data type does the variable 'name' have?
Explanation: When you assign text within quotes to a variable in Python, such as 'Alice', its data type is string. 'Integer' is for whole numbers, which doesn't fit here. 'Float' represents decimal numbers, and 'boolean' is for True or False values, making them incorrect in this case.
What will happen if you forget to indent the code inside a Python 'for' loop?
Explanation: Forgetting to indent inside a Python loop leads to an IndentationError because indentation defines blocks in Python. The code will not run without errors if indentation is missing. Indentation is not optional in Python. The interpreter will not simply skip the loop but will instead stop with an error.
Which symbol is used to start a single-line comment in Python?
Explanation: The '#' symbol begins a single-line comment in Python, making any text after it on the same line ignored by the interpreter. '//' is used in some other languages, but doesn't comment in Python. '--' and '/*' are not recognized as comment symbols in Python; they are used elsewhere.
Which Python keyword is used to create a loop that repeats while a given condition is True?
Explanation: The 'while' keyword initializes a loop that continues as long as the specified condition remains True in Python. 'repeat', 'until', and 'loop' are not valid Python keywords for looping; they may be used in other languages or are simply incorrect here. Only 'while' functions correctly for this purpose.