Python Methods

print() – prints whatever is inside the parentheses.

.title() – changes each word to title case.

.upper() – changes string to all uppercase.

.lower() – changes string to all lowercase.

\t – adds tab to text.

\n – adds a new line to text.

.rstrip() – removes white space to right of string.

.lstrip() – removes white space to left of string.

.strip() – removes white space on both sides of string.

.removeprefix() – removes prefix from a string.

.removesuffix() – removes suffix from a string.

(+) – adds.

(-) – subtracts.

(*) – multiplies.

(/) – divides.

(**) – exponents.

[ ] – denotes a list, with elements inside separated by commas.

.append() – adds a new item to the end of a list.

.insert() – inserts a new item in a list.

del – removes an item from a list if you know its position.

pop() – removes the last item from a list, but lets you work with that item after removing it.

remove() – removes an item from a list if you know the value.

sort() – sorts a list in alphabetical order. It changes the order of the list permanently. You can sort a list in reverse-alphabetical order by passing the argument reverse=True to the sort() method.

sorted() – sorts a list without changing the actual order of the list. Can also accept a reverse=True argument if you want to display a list in reverse-alphabetical order.

reverse() – reverses the original order of a list. It changes the order of the list permanently, but you can go back to the original order by applying reverse() a second time.

len() – finds the length of a list.

range() – makes it easy to generate a series of numbers. You can pass three values to the range function, a starting value, an ending value, and a step value.


Posted

in

by