GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 3 von 5 · Text

Ohne Titel

Bhavuk kumar

Important Topics Continue:

3. Lists : 
- lists of files in a folder, employees in a company, emails in your inbox, and so on.
- Python’s lists may be reminiscent of arrays in other languages, but they tend to be more powerful.
- Further, lists have no fixed size. That is, they can grow and shrink on demand, in response to list-specific operations:

>>> L = [123, 'spam', 1.23]   # A list of three different-type objects
>>> len(L)                               # Number of items in the list
3

>>> L[0]                                 # Indexing by position
123
>>> L[:-1]                               # Slicing a list returns a new list
[123, 'spam']
>>> L + [4, 5, 6]                      # Concat/repeat make new lists too
[123, 'spam', 1.23, 4, 5, 6]
>>> L * 2
[123, 'spam', 1.23, 123, 'spam', 1.23]
>>> L                                       # We're not changing the original list
[123, 'spam', 1.23]

>>> L.append('NI')                # Growing: add object at end of list
>>> L
[123, 'spam', 1.23, 'NI']
>>> L.pop(2)                           # Shrinking: delete an item in the middle
1.23
>>> L                                        # "del L[2]" deletes from a list too
[123, 'spam', 'NI']

>>> M = ['bb', 'aa', 'cc']
>>> M.sort()
>>> M
['aa', 'bb', 'cc']
>>> M.reverse()
>>> M
['cc', 'bb', 'aa']>>> M = ['bb', 'aa', 'cc']
>>> M.sort()
>>> M
['aa', 'bb', 'cc']
>>> M.reverse()
>>> M
['cc', 'bb', 'aa']

 

 

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck