Can someone please explain to me types in python especially lists, list comprehension and slices | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

Can someone please explain to me types in python especially lists, list comprehension and slices

29th Sep 2020, 3:48 PM
Rootcreator
Rootcreator - avatar
3 Réponses
+ 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.
29th Sep 2020, 4:01 PM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 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
29th Sep 2020, 4:11 PM
Lothar
Lothar - avatar
29th Sep 2020, 4:11 PM
Abhay
Abhay - avatar