xFazz

Python notes

Jun 9th, 2021 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. len() -> Counts how many
  2. round() -> Rounds
  3. sum() -> Adds up values
  4. max() -> Find max in a series of values
  5. min() -> Find min in a series of values
  6. .split() -> To split apart a string, by default by space
  7. shuffle() -> Shuffles the elements of a list
  8. .index() -> Determine the index of the argument passed in a data structure
  9. ceil()
  10. math.isclose() -> Determine if two numbers are close to each other
  11.  
  12. list.append(elem) -- adds a single element to the end of the list. Common error: does not return the new list, just modifies the original.
  13. list.insert(index, elem) -- inserts the element at the given index, shifting elements to the right.
  14. list.extend(list2) adds the elements in list2 to the end of the list. Using + or += on a list is similar to using extend().
  15. list.index(elem) -- searches for the given element from the start of the list and returns its index. Throws a ValueError if the element does not appear (use "in" to check without a ValueError).
  16. list.remove(elem) -- searches for the first instance of the given element and removes it (throws ValueError if not present)
  17. list.sort() -- sorts the list in place (does not return it). (The sorted() function shown later is preferred.)
  18. list.reverse() -- reverses the list in place (does not return it)
  19. list.pop(index) -- removes and returns the element at the given index. Returns the rightmost element if index is omitted (roughly the opposite of append()).
  20.  
  21.  
  22. if (condition):
  23. pass
  24.  
  25.  
  26. In a flow chart, consider every step the program has to take to get to the end. One start, one end
  27.  
  28. https://stackoverflow.com/questions/46674581/wrap-list-around-in-python
  29. https://stackoverflow.com/questions/5180365/python-add-comma-into-number-string
Add Comment
Please, Sign In to add comment