0

Python

Pls how do they code this is in python App {"solo","learn",killer","bean"} Print{2}

17th Mar 2025, 2:07 AM
Chima Akachukwu
Chima Akachukwu - avatar
2 Answers
+ 6
This seems like a set as the items are placed in curly braces, and the code is supposed to output the third item(2nd index) from App. App = {"solo", "learn", "killer", "bean"} print(App[2]) But this would raise a TypeError because sets are unordered and you can't access its items by index. If you meant to use an ordered collection, you likely meant using list(items in square brackets): App = ["solo", "learn", "killer", "bean"] print(App[2]) #outputs killer
17th Mar 2025, 3:22 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
+ 6
Chima Akachukwu another way to look at this is sets are "Unordered" while lists and tuples are Ordered / indexed... Imagine having a bag of marbles and not a linear tray so each time you reach in the bag you never know which marble you are going to grab first, second, third, fourth, and so on. https://sololearn.com/compiler-playground/c3gPDv24ARHh/?ref=app
17th Mar 2025, 3:47 AM
BroFar
BroFar - avatar