Last Updated on July 9, 2022 by shibatau
The link to Python 6-If Statements is added.
I. What will you learn?
These posts are Python tutorials for beginners and used for my lectures.
There are three types of functions in Python:
- Built-in functions: you can find an overview with them here.
- User-Defined Functions (UDFs)
- Anonymous functions (Lambda functions): they are not declared with the standard def keyword.
Here are sample scripts in Cheat Sheets Basics V:
Define a function def plus(a, b): return a + b Lambda functions plus = lambda a, b: a + b plus(10, 20) # 30 Enumerate ls = ['a', 'c', 'b'] print(list(enumerate(ls))) # [(0, 'a'), (1, 'c’), (2, 'b')] Sort sorted(ls) # ['a', 'b', 'c'] Reverse list(reversed(ls)) Map ls = ['abc', 'def'] list(map(lambda x: x.upper(), ls)) # ['ABC', 'DEF'] Reduce from functools import reduce ls = [10, 20, 30] total = reduce(lambda a, b: a + b, ls) total # 60
You can see the scripts here: