0

# Lists Operations

What is the result of this code? nums = [10, 9, 8, 7, 6, 5] nums = nums - 5 if 4 in nums: print(nums) else: print(nums) Explain me this question.

16th Aug 2020, 1:35 PM
Jash Sampat
+ 1
num returns the elements at 1st index of nums that is 9 ,so 9-5=4 nums=4 ,list looks like this now [4,9,8,7,6,5] if 4 in nums: check if number 4 is in list or not and since it is in list condition is satisfied and following statement is executed, print(num which prints the element in num at 3rd index which is 7
16th Aug 2020, 1:40 PM
Abhay + 7
kirit sampat , i am sure that it will be a big benefit for for your learning progress if you are going (to continue) to work through the python tutorial here in sololearn. To get successful in coding, you need to know and get familiar with these basics. also do practice with simple python challenges. Happy coding.
16th Aug 2020, 2:39 PM
Lothar + 1
Output is 7 because, nums = nums-5 means nums = 9-5 = 4 (nums = 9). It adds 4 at the beginning of the list. The if condition test if 4 in the list. If 4 is in list it prints nums = 7. I hope you understand.
16th Aug 2020, 1:44 PM
Allamprabhu Hiremath
0
num returns the elements at 1st index of nums that is 9 ,so 9-5=4 nums=4 ,list looks like this now [4,9,8,7,6,5] if 4 in nums: check if number 4 is in list or not and since it is in list condition is satisfied and following statement is executed, print(num which prints the element in num at 3rd index which is 7
23rd Oct 2021, 1:28 PM
Ngozichukwu Iheanyi