0

Почему в консоль выводится исходный список

arr = [4,3,1,2] arr[0], arr[arr[0]-1] == arr[arr[0]-1], arr[0] print(arr)

4th Oct 2023, 8:01 PM
Антон Баранов
Антон Баранов - avatar
3 Answers
+ 2
# Почему в консоль выводится исходный список # Why is the original list displayed in the console? arr = [4,3,1,2] print(arr[0], arr[3] == arr[3], arr[0]) print(arr) # the equality operator == checks if two values are equal print(1 == 4) # the assignment operator = assigns a value to a variable num = 5 print(num) arr[0] = 10 print(arr)
4th Oct 2023, 11:10 PM
Mafdi
Mafdi - avatar
+ 1
Although line 2 looks like is comparing values, actually it is not. It prints nothing and didn't change the original list. Line 2's explanation. arr[0], arr[arr[0]-1] == arr[arr[0]-1], arr[0] 4, arr[4-1] == arr[4-1], 4 4, arr[3] == arr[3], 4 4, 2 == 2, 4 (4, True, 4) # line 2 is evaluated into a tuple After line 2 is evaluated it does nothing and original list arr is unchanged. Thus printing arr return the original list.
5th Oct 2023, 1:37 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
По тому что Вы скорее всего спутали оператор сравнения "==" с оператором присваивания "=".
5th Oct 2023, 8:15 PM
Solo
Solo - avatar