+ 2
Can someone please explain to me types in python especially lists, list comprehension and slices
3 ответов
+ 5
A list is a data type in python. In other programming languages they are mostly called Arrays. Here's an example of one:
numbers = [1, 2, 3, 4, 5]
With list slices you can access list elements:
print(numbers[0:5]) #prints all numbers in the list, because lists indexing starts from 0
print(numbers[0:5:2]) #prints only odd numbers
(the first argument is what element to start from, second is what element to go to and third is step)
Slices can also be used to reverse a list: print(numbers[::-1]). As "from" and "to" values are omitted, the whole list is used and the step is negative, so the list will be reversed.
+ 5
Additional to the post of Akbar, see also this items about lists: (you can find things like these in Learn section of the app and using the search bra)
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2433/ list functions
https://www.sololearn.com/learn/Python/2432/ list operations
https://www.sololearn.com/learn/685/ Linked lists
+ 1
Arrays and lists are different tho Artem
https://www.quora.com/What-is-the-difference-between-an-ARRAY-and-a-LIST?top_ans=208546318