+ 1
Why does nums[1]=22
10 Réponses
+ 1
# | 0 | 1 | 2 | Indices
nums = [34, 42, 56] #Items
stupid_variable = 80
#You can use these items like variables, but you need to use indexing to specify which item you want to use.
print(stupid_variable)
#Output: 80
print(nums[0])
#Output: 34
#Reassing variable:
stupid_variable = 15
#Reassing item of index 1 to 22:
nums[1] = 22
print(stupid_variable)
#Output: 15
print(nums)
#Output: [34, 22, 56]
0
You might want to be a little more specific if you actually want an answer :/
0
for the problem:
nums[34,42,56]
nums[1]=22
print[nums]
0
the directions were to finish the list, rearrange the second value, and to print the whole list
0
Olay there are a few problems. In the first line, you actually have to assign the values:
nums = [34, 42, 56]
The second line was fine, but in the third line, with function arguments are written in parentheses, not square brackets:
print(nums)
0
ya thats what i meant lol
0
So what is your question?
0
you have the full codes ? maybe there's a logic error somewhere in your code
0
the code was:
nums=[34, 42, 56]
nums[1]=22
print(nums)
0
and what did you expect for the output ?