list operations | Sololearn: Learn to code for FREE!

0

list operations

What is the result of this code? nums = [10, 9, 8, 7, 6, 5] nums[0] = nums[1] - 5 if 4 in nums: print(nums[3]) else: print(nums[4]) How does this works?

4/16/2020 8:39:19 AM

PRIYANKA K

2 Answers

New Answer

+2

nums = [10, 9, 8, 7, 6, 5] nums[0] = nums[1] - 5 # change 1st element with 2nd element minus 5 (9 - 5 -> 4) print(nums) # see how <nums> had changed, 1st element is now 4, not 10 anymore if 4 in nums: # does <num> contain 4? yes print(nums[3]) # print the 4th list element -> 7 else: # if <nums> doesn't contain 4 print(nums[4]) # print the 5th list element -> 6

+1

What don't you understand ? The "in" ?