Difference between revisions of "Python: def"
Jump to navigation
Jump to search
| (23 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | {{ | + | {{lowercase}} |
| + | <code>def</code> [[keyword]] to define a [[Python]] [[function]] | ||
| + | * https://docs.python.org/3/tutorial/controlflow.html#defining-functions | ||
| − | |||
| + | * <code>def [[lambda_handler]](event, context):</code> | ||
| − | def [[ | + | |
| + | Define it: | ||
| + | def YourFirstFunction(): | ||
| + | [[print]] ("My first function") | ||
| + | |||
| + | Use to execute it: | ||
| + | YourFirstFunction() | ||
| + | |||
| + | |||
| + | |||
| + | def main(): | ||
| + | # my code here | ||
| + | |||
| + | [[if __name__ == "__main__":]] | ||
| + | main() | ||
| + | |||
| + | == Related terms == | ||
| + | * [[Variables]] | ||
| + | * <code>[[return]]</code> | ||
| + | * <code>__[[init]]__</code> | ||
| + | * <code>[[Python classes|class]] your_first_class:</code> | ||
| + | * <code>[[try:]]</code> | ||
| + | * <code>[[if name == " main ":]]</code> | ||
| + | * [[function]] | ||
== See also == | == See also == | ||
Latest revision as of 19:50, 26 March 2024
def keyword to define a Python function
def lambda_handler(event, context):
Define it:
def YourFirstFunction(): print ("My first function")
Use to execute it:
YourFirstFunction()
def main():
# my code here
if __name__ == "__main__":
main()
Related terms[edit]
See also[edit]
- Python, PIP, Global interpreter lock (GIL), Flask, Django, Marshmallow,
def, logging, Pandas, Numpy, AWS Chalice,import,from,tuple,list, Python exceptions,virtualenv,.append,pytz,TZ,print,python3 -c,os, PEP, Python Institute, Methods: Dunder methods, Flake8, Python collections, Function decorators in Python, Click python library, Python module, Flower,kwargs, Black (Python), Python list structure, Mypy,variables, Casting,try:, pydoc, argparse, Anaconda,pyenv, setup.py, python3 --version, python3 --help, Data Classes, raise, glob
Advertising: