if nums [3] = nums [1], then nums [1] = nums [3], therefore the output will not be 2, but 4. Why then output 2? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

if nums [3] = nums [1], then nums [1] = nums [3], therefore the output will not be 2, but 4. Why then output 2?

Is mathematics in programming something different from ordinary mathematics? Explain. https://code.sololearn.com/ceTkzAA5NhHv/?ref=app

15th Aug 2020, 9:14 AM
иван
иван - avatar
4 Answers
+ 3
U change the value of num[3] by the value of num[1] but u must know the value of num[1] still be fixed If u want the value of num[1] = the value of num[3] u should write num[1] =num[3] = 4 . In this case there are have the same value
15th Aug 2020, 9:22 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 2
= in programming is an assignment operator, it means "becomes" when you said nums[3]=nums[1] you nums[3] becomes nums[1] so nums[3]=2
15th Aug 2020, 9:22 AM
Andrei I
Andrei I - avatar
+ 1
Hey иван In Your Code You’re Using Assignment Operator Which Will Assign The Value Of One Variable To Another Variable. So In Your Solution nums=[1,2,3,4,5] nums[3]=nums[1] In Above Statement You Assigned The Value Of Index 1 To Index 3. So Now Your List Is Updated nums=[1,2,3,2,5] And print(nums[3]) Gives You Output - 2. And This Happened Because List Is Mutable.
15th Aug 2020, 9:24 AM
Rahul Saxena
Rahul Saxena - avatar
+ 1
thanks everyone! now I understand
15th Aug 2020, 10:46 AM
иван
иван - avatar