Why does nums[1]=22 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does nums[1]=22

2nd Jul 2019, 5:02 AM
LP13
LP13 - avatar
10 Answers
+ 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]
2nd Jul 2019, 9:37 AM
Seb TheS
Seb TheS - avatar
0
You might want to be a little more specific if you actually want an answer :/
2nd Jul 2019, 5:04 AM
Airree
Airree - avatar
0
for the problem: nums[34,42,56] nums[1]=22 print[nums]
2nd Jul 2019, 5:05 AM
LP13
LP13 - avatar
0
the directions were to finish the list, rearrange the second value, and to print the whole list
2nd Jul 2019, 5:07 AM
LP13
LP13 - avatar
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)
2nd Jul 2019, 5:10 AM
Airree
Airree - avatar
0
ya thats what i meant lol
2nd Jul 2019, 5:11 AM
LP13
LP13 - avatar
0
So what is your question?
2nd Jul 2019, 5:12 AM
Airree
Airree - avatar
0
you have the full codes ? maybe there's a logic error somewhere in your code
2nd Jul 2019, 5:49 AM
Taste
Taste - avatar
0
the code was: nums=[34, 42, 56] nums[1]=22 print(nums)
2nd Jul 2019, 5:51 AM
LP13
LP13 - avatar
0
and what did you expect for the output ?
2nd Jul 2019, 5:52 AM
Taste
Taste - avatar