0
Lists 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]) Explain me this question.
4 Respostas
+ 1
num[1] returns the elements at 1st index of nums that is 9 ,so 9-5=4
nums[0]=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[3] which prints the element in num at 3rd index which is 7
+ 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.
+ 1
Output is 7 because, nums[0] = nums[1]-5 means nums[0] = 9-5 = 4 (nums[1] = 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[3] = 7.
I hope you understand.
0
num[1] returns the elements at 1st index of nums that is 9 ,so 9-5=4
nums[0]=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[3] which prints the element in num at 3rd index which is 7