Computer Science
Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
- [0, 1, 2, 3]
- [0, 1, 2, 3, 4]
- [0.0, 0.5, 1.0, 1.5]
- [0.0, 0.5, 1.0, 1.5, 2.0]
Python List Manipulation
1 Like
Answer
[0.0, 0.5, 1.0, 1.5]
Reason — The list comprehension [0.5 * x for x in range(0, 4)]
generates a list by calculating 0.5 * x for each value of x in the range from 0 to 3 (not including 4), which results in the list [0.0, 0.5, 1.0, 1.5].
Answered By
1 Like
Related Questions
What will be the output when the following code is executed?
>>> strl = "helloworld" >>> strl[ : : -1]
- dlrowolleh
- hello
- world
- helloworld
What is the output of the following statement?
python print("xyyzxyzxzxyy".count('yy', 1))
- 2
- 0
- 1
- Error
Which is the correct form of declaration of dictionary ?
- Day = {1:'Monday', 2:'Tuesday', 3:'wednesday'}
- Day = {1;'Monday', 2;'Tuesday', 3;'wednesday'}
- Day = [1:'Monday', 2:'Tuesday', 3:'wednesday']
- Day = {1'monday', 2'tuesday', 3'wednesday'}
Identify the valid declaration of L:
L = [1, 23, 'hi', 6]
- list
- dictionary
- array
- tuple