Exercise: Data Types

Questions for: Data Types

What is the purpose of the len() function?
A:
To calculate the logarithm
B:
To find the length of a string or list
C:
To generate random numbers
D:
To perform mathematical operations
Answer: B
The len() function is used to determine the number of elements in a string, list, or any other iterable object.
Which of the following is a valid Python string?
A:
'Hello, World!"
B:
"Hello, World!'
C:
'Hello, World!'
D:
None of these
Answer: C
Both single and double quotes are valid for creating strings, but they must be matched properly.
What is the correct way to comment a single-line?
A:
// This is a comment
B:
/* This is a comment */
C:
# This is a comment
D:
-- This is a comment
Answer: C
In Python, single-line comments are made using the '#' symbol.
What is the correct way to declare a variable?
A:
var x = 5
B:
int x = 5
C:
x = 5
D:
variable x = 5
Answer: C
In Python, variables can be declared simply by assigning a value to them. No explicit type declaration is needed.
Which of the following data types is used to represent a sequence of Unicode characters that cannot be modified?
A:
int
B:
float
C:
str
D:
bytes
Answer: C
The str data type is used to represent a sequence of Unicode characters that cannot be modified. It is immutable.
Ad Slot (Above Pagination)
Quiz