![]() |
|
[Tut] Python List Methods Cheat Sheet [Instant PDF Download] - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: Python (https://sickgaming.net/forum-83.html) +--- Thread: [Tut] Python List Methods Cheat Sheet [Instant PDF Download] (/thread-94543.html) |
[Tut] Python List Methods Cheat Sheet [Instant PDF Download] - xSicKxBot - 04-14-2020 Python List Methods Cheat Sheet [Instant PDF Download] Here’s your free PDF cheat sheet showing you all Python list methods on one simple page. Click the image to download the high-resolution PDF file, print it, and post it to your office wall: ![]() Instant PDF Download [100% FREE] I’ll lead you through all Python list methods in this short video tutorial: If you want to study the methods yourself, have a look at the following table from my blog article: Method | Description Code: lst.append(x)Appends element Code: xCode: lstCode: lst.clear()Removes all elements from the list Code: lstCode: lst.copy()Returns a copy of the list Code: lstCode: lst.count(x)Counts the number of occurrences of element Code: xCode: lstCode: lst.extend(iter)Adds all elements of an iterable Code: iterCode: lstCode: lst.index(x)Returns the position (index) of the first occurrence of value Code: xCode: lstCode: lst.insert(i, x)Inserts element Code: xCode: iCode: lstCode: lst.pop()Removes and returns the final element of the list Code: lstCode: lst.remove(x)Removes and returns the first occurrence of element Code: xCode: lstCode: lst.reverse()Reverses the order of elements in the list Code: lstCode: lst.sort()Sorts the elements in the list Code: lstGo ahead and try the Python list methods yourself: https://repl.it/repls/UnevenHoneydewOctagon?lite=true Puzzle: Can you figure out all outputs of this interactive Python script? If you’ve studied the table carefully, you’ll know the most important list methods in Python. Let’s have a look at some examples of above methods: Code: >>> l = []
>>> l.append(2)
>>> l
[2]
>>> l.clear()
>>> l
[]
>>> l.append(2)
>>> l
[2]
>>> l.copy()
[2]
>>> l.count(2)
1
>>> l.extend([2,3,4])
>>> l
[2, 2, 3, 4]
>>> l.index(3)
2
>>> l.insert(2, 99)
>>> l
[2, 2, 99, 3, 4]
>>> l.pop()
4
>>> l.remove(2)
>>> l
[2, 99, 3]
>>> l.reverse()
>>> l
[3, 99, 2]
>>> l.sort()
>>> l
[2, 3, 99]Want more cheat sheets? Excellent. I believe learning with cheat sheets is one of the most efficient learning techniques. Join my free Python email listwhere I’ll send you more than 10 new Python cheat sheets and regular Python courses for continuous improvement. It’s free! |