Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. # .title to Capitalize the first letter of every word in our list.
  2. # .strip to strip out all white space from the variable
  3. name = 'tarik '
  4. print(name.title().strip())
  5.  
  6. players = ['tarik', 'stewie', 'shroud', 'skadoodle', 'seangares']
  7. print(f"My favorite player is: {players[0].title()}")
  8.  
  9. # .append to add a variable to the end of our list
  10. players.append('shoxieJESUS')
  11. print (players[-1])
  12.  
  13. # We can add a variable to our list in a specific index spot like below
  14. players[0] = 'flusha'
  15. print(players[0])
  16.  
  17. # .insert to add a value to our list with the params (indexValue, variable)
  18. players.insert(2, 'twistz')
  19. print(players[2])
  20.  
  21. # We can use del() to delete objects like classes, variables, list variables, etc
  22. del players[0]
  23. print(players)
  24. del name
  25.  
  26. # .pop to remove and return the last value in our list
  27. # We can also pop a specific index value with .pop(indexValue)
  28. print(f"We're going to get rid of our favorite player: {players.pop()}")
  29.  
  30. # We can use .remove if we don't know the index value of the item we want to remove from the list
  31. players.remove('stewie')
  32. print (players)
  33.  
  34. # We can re-arrange our list permanently alphabetically using .sort
  35. # We can also sort it in reverse alphabetical order with .sort(reverse=TRUE)
  36. players.sort()
  37. print(players)
  38. players.sort(reverse=True)
  39. print(players)
  40.  
  41. # If we don't want to re-arrange our list permanently we can use sorted()
  42. print(sorted(players))
  43.  
  44. # If we want to reverse the list but not alphabetically we can use .reverse()
  45. players.reverse()
  46. print(players)
  47.  
  48. # We want find the length of a list using len()
  49. print(len(players))
  50. amountOfPlayers = len(players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement