Python Methods and Functions Cheat Sheet
Hello World here are 3 Python cheat sheet tips that all junior developers should know. These are very important to remember and will help you become a better developer.
1.) sum() — max() — min()
The sum() function allows you to add all the numbers in a list.
ex.) numbers = [2, 15, 7, 10, 32]
sum(numbers) // 66
The max() function will allow you to get the largest number in a list, and the min() function will allow you to get the smallest number.
numbers = [2, 15, 7, 10, 32]
max(numbers) // 32
min(numbers) // 2
2.) random.choice
Random.choice allows you to grab a random item within a list. This is very helpful when you are doing anything with randomization such as choosing a random name from a list, choosing a random question for a quiz, etc. Make sure to — import random — at the top of the page as well or the code will not work.
import random
numbers = [2, 15, 7, 10, 32]
random.choice(numbers) // 10
random.choice(numbers) // 2
3.) .lower()