1. What is the data type of the following Python variable: x = 5?
Answer:
Explanation:
In Python, the variable 'x' assigned with a whole number (without a decimal point) is of integer type.
2. Which data type in Python is used to store a sequence of characters?
Answer:
Explanation:
Python uses the string data type to store sequences of characters.
3. What data type would be used for a variable that holds the value 3.14 in Python?
Answer:
Explanation:
The float data type in Python represents floating-point numbers, which are numbers with a decimal point.
4. How is a list defined in Python?
Answer:
Explanation:
Lists in Python are defined using square brackets and can contain elements of different data types.
5. What type of data does a Python tuple store?
Answer:
Explanation:
A tuple in Python is a collection of Python objects that are immutable (cannot be changed after creation).
6. What is the data type of the following Python variable: x = True?
Answer:
Explanation:
The variable 'x' in Python with the value True is of Boolean type, representing the logical values True or False.
7. What is a dictionary in Python?
Answer:
Explanation:
In Python, a dictionary is a collection of key-value pairs where each key is unique and used to retrieve its corresponding value.
8. Which of the following is a mutable data type in Python?
Answer:
Explanation:
Lists in Python are mutable, meaning their elements can be changed after their creation.
9. How do you define a set in Python?
Answer:
Explanation:
A set in Python is defined using curly braces and is an unordered collection of unique elements.
10. What is the output of the following Python code: type(8)?
Answer:
Explanation:
The type() function in Python shows that the value 8 is of integer class, denoted as <class 'int'>.
11. Which of the following data types does not allow duplicate values in Python?
Answer:
Explanation:
Sets in Python are collections of unique elements, meaning they do not allow duplicate values.
12. What is the correct syntax to create an empty list in Python?
Answer:
Explanation:
An empty list in Python can be created using square brackets without any elements inside.
13. Which Python data type is used for ordered collections of items?
Answer:
Explanation:
Lists in Python are used for storing ordered collections of items and are one of the most versatile data types available.
14. What is the data type of the following Python variable: x = {"name": "John", "age": 30}?
Answer:
Explanation:
The variable 'x' is a dictionary in Python, as it is defined with curly braces containing key-value pairs.
15. In Python, what data type is best suited for storing a binary number like 0b1101?
Answer:
Explanation:
Python stores binary numbers (e.g., 0b1101) as integers. The '0b' prefix indicates a binary literal.
16. What is the data type of the following Python variable: x = 3.14j?
Answer:
Explanation:
The 'j' suffix in Python denotes a complex number, making x a complex number with an imaginary part.
17. Which of the following Python data types is immutable?
Answer:
Explanation:
Tuples in Python are immutable, meaning that their elements cannot be modified after they have been created.
18. What is the data type of the following Python variable: x = b"Hello"?
Answer:
Explanation:
The variable 'x' is a byte type in Python, indicated by the 'b' prefix before the string literal.
19. How do you define an integer variable 'a' in Python with the value 1000?
Answer:
Explanation:
In Python, a variable is assigned a value using the '=' operator without specifying the data type.
20. What is the correct way to define a hexadecimal number in Python?
Answer:
Explanation:
In Python, hexadecimal numbers are represented by prefixing the number with '0x' or '0X'.
Comments
Post a Comment
Leave Comment