+ 3
What is the result of this code? nums = [1, 2, 3, 4, 5] nums[3] = nums[1] print(nums[3])
why is the answer not 4?
11 odpowiedzi
+ 9
The output is 2.
Because you wrote there that
num[3] = nums[1]
It simply means that
you reassigned 4 to 2 i.e
4=2(not the correct way,just to explain)
So, it assigned 4 to 2.
That's why the output is not 4 but 2.
You haven't assigned 2 to 4. If you want to do so then, it should be:-
nums = [1, 2, 3, 4, 5]
nums[1] = nums[3]
print(nums[1]) # now outputs 4
Hope it's clear now 🙂
+ 2
because 4 was switched with 2. index assignment good sir
+ 1
Because the value of num[1], which is 2, has been assign to num[3], so num[3] has become equal to the value of num[1].
it print 2.
0
Because nums[1] which is 2 is stored in place of num[3].
Now when you print it gives 2.
0
diles
0
0
2
0
2
0
Can you determine the output of this code:
nums = [1, 3, 5, 2, 4]
res = min(nums) + max(nums)
print(res)
0
Is Ans
2
0
4