What is the correct way to create a variable in Python?
Python variables are created using the assignment operator (=) with valid identifiers containing letters, digits, and underscores.
Which of the following is NOT a valid Python identifier?
Python identifiers cannot start with a digit. They must begin with a letter or underscore.
What will be the output of: print(type(5.0))?
5.0 is a floating-point number in Python. The type() function returns <class 'float'> for decimal numbers.
Which keyword is used to create a function in Python?
The 'def' keyword is used to define functions in Python. It is followed by the function name and parameters.
What will be the output of: len('Python')?
The string 'Python' has 6 characters: P, y, t, h, o, n. The len() function returns the number of characters.
Advertisement
Which statement about Python comments is correct?
Python comments start with # and can appear anywhere. Multi-line comments use triple quotes or multiple # symbols.
What will be the output of: print(type(25))?
The division operator (/) in Python 3 always returns a float, even if both operands are integers.
Which of the following keywords is used to create a function in Python?
The 'def' keyword is used to define a function in Python. Other options are not valid Python keywords.
What will be the output of: print("Python"[2:5])?
String slicing [2:5] extracts characters from index 2 to 4 (5 is exclusive). 'Python'[2:5] = 'yth'.
What is the output of: print(10 // 3)?
The floor division operator (//) returns the quotient rounded down to the nearest integer. 10 // 3 = 3.
Which of the following is an immutable data type in Python?
Tuples are immutable, meaning their elements cannot be changed after creation. Lists, dictionaries, and sets are mutable.
What will be the output of: len('hello world')?
The len() function counts all characters including the space. 'hello world' has 11 characters (including 1 space).
Which of the following will correctly concatenate two strings 'Hello' and 'World'?
The + operator concatenates strings in Python. Other operators don't perform string concatenation.
What is the correct way to create a dictionary in Python?
Dictionaries in Python use curly braces with key-value pairs separated by colons.
Which of the following statements about Python tuples is correct?
Tuples are immutable sequences in Python, meaning their contents cannot be changed once created.
What will be the output of: x = 5; y = 10; print(x == y)
The comparison operator == checks if x equals y. Since 5 ≠ 10, the result is False.
What does len() function return when applied to a string?
The len() function returns the number of characters (length) in a string.
What will be the output of: print(type(3.14))
3.14 is a floating-point number, so type() returns <class 'float'>.
In Python, which of the following is an immutable data type?
Tuples are immutable in Python, meaning their elements cannot be changed after creation. Lists, dictionaries, and sets are all mutable.
What will be the result of executing: print(type(5.0))?
5.0 is a floating-point number, so type(5.0) returns <class 'float'>.