+ 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?

5th Jul 2020, 11:37 AM
Jaagrit Arora
Jaagrit Arora - avatar
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 🙂
5th Jul 2020, 11:46 AM
Arctic Fox
Arctic Fox - avatar
+ 2
because 4 was switched with 2. index assignment good sir
5th Jul 2020, 11:41 AM
Slick
Slick - avatar
+ 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.
5th Jul 2020, 6:36 PM
Noria Soltani
Noria Soltani - avatar
0
Because nums[1] which is 2 is stored in place of num[3]. Now when you print it gives 2.
5th Jul 2020, 11:42 AM
Blue!!
Blue!! - avatar
0
diles
2nd Jun 2021, 9:30 AM
Bruno Hausmann Rademakers
Bruno Hausmann Rademakers - avatar
0
8th Jun 2021, 9:45 AM
اورد عبدالامير جاسم _المرحلة الثانية شعبة[ A]
اورد عبدالامير جاسم _المرحلة الثانية شعبة[ A] - avatar
0
2
9th Nov 2021, 6:10 AM
lulwa ali
0
2
23rd Apr 2022, 4:33 PM
Hamdy Elredi
Hamdy Elredi - avatar
0
Can you determine the output of this code: nums = [1, 3, 5, 2, 4] res = min(nums) + max(nums) print(res)
23rd Dec 2022, 3:55 PM
ADVENSIA EVARISTA HALE
ADVENSIA EVARISTA HALE - avatar
0
Is Ans 2
13th Jan 2023, 3:57 PM
Engr.Ayesha Liaqat
Engr.Ayesha Liaqat - avatar
0
4
23rd Jan 2023, 7:21 AM
Vikram Kumar Sinha
Vikram Kumar Sinha - avatar