Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # .title to Capitalize the first letter of every word in our list.
- # .strip to strip out all white space from the variable
- name = 'tarik '
- print(name.title().strip())
- players = ['tarik', 'stewie', 'shroud', 'skadoodle', 'seangares']
- print(f"My favorite player is: {players[0].title()}")
- # .append to add a variable to the end of our list
- players.append('shoxieJESUS')
- print (players[-1])
- # We can add a variable to our list in a specific index spot like below
- players[0] = 'flusha'
- print(players[0])
- # .insert to add a value to our list with the params (indexValue, variable)
- players.insert(2, 'twistz')
- print(players[2])
- # We can use del() to delete objects like classes, variables, list variables, etc
- del players[0]
- print(players)
- del name
- # .pop to remove and return the last value in our list
- # We can also pop a specific index value with .pop(indexValue)
- print(f"We're going to get rid of our favorite player: {players.pop()}")
- # We can use .remove if we don't know the index value of the item we want to remove from the list
- players.remove('stewie')
- print (players)
- # We can re-arrange our list permanently alphabetically using .sort
- # We can also sort it in reverse alphabetical order with .sort(reverse=TRUE)
- players.sort()
- print(players)
- players.sort(reverse=True)
- print(players)
- # If we don't want to re-arrange our list permanently we can use sorted()
- print(sorted(players))
- # If we want to reverse the list but not alphabetically we can use .reverse()
- players.reverse()
- print(players)
- # We want find the length of a list using len()
- print(len(players))
- amountOfPlayers = len(players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement