What is a List?
One of the Sequence Types is list.
It is used to store variables: list_ = [1, 3, 6, 'a', True]. To create a list, you just need to put variables inside square brackets.
You can't name a variable as a data type: list_ is OK.
Indices
The list's first item has the index 0, the next one 1, and so on. If we start from the end, the last item has the index -1, and the second-to-last has the index -2, and so on.
123456list_ = ['P', 'y', 't', 'h', 'o', 'n'] print('The first item is', list_[0]) print('The third item is', list_[2]) print('The fifth item is', list_[-2]) print('The last item is', list_[-1])
Takk for tilbakemeldingene dine!
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 2.7
What is a List?
Sveip for å vise menyen
One of the Sequence Types is list.
It is used to store variables: list_ = [1, 3, 6, 'a', True]. To create a list, you just need to put variables inside square brackets.
You can't name a variable as a data type: list_ is OK.
Indices
The list's first item has the index 0, the next one 1, and so on. If we start from the end, the last item has the index -1, and the second-to-last has the index -2, and so on.
123456list_ = ['P', 'y', 't', 'h', 'o', 'n'] print('The first item is', list_[0]) print('The third item is', list_[2]) print('The fifth item is', list_[-2]) print('The last item is', list_[-1])
Takk for tilbakemeldingene dine!