Python Functions Explained: Your First Function, Step by Step
Mrs. Tech
0:00 / 0:00
Python Functions Explained: Your First Function, Step by Step
126 просмотров · 3 нед. назад
Mrs. Tech
15 подписчиков
126 просмотров · 3 нед. назад
Write your first Python function, step by step: def, the colon, the indented body, calling it, parameters and arguments, default values, return, and docstrings. Plus the three mistakes every beginner makes, and why functions make your code easier to read and fix.
Challenge: write a function called square that returns a number times itself, and post it in the comments.
CHAPTERS
0:00 Why functions
0:17 What a function is
0:32 def, name, parentheses, colon
0:49 The indented body
1:03 Calling a function
1:32 Parameters
2:01 Default values
2:14 return
3:18 Docstrings
3:31 Why functions matter
4:02 3 common mistakes
4:34 Recap and challenge
Examples follow the official Python tutorial (section 4.8, Defining Functions), with PEP 8 indentation and PEP 257 docstrings. Python 3.
SOURCES
Python tutorial: Defining Functions
https://docs.python.org/3/tutorial/control...
PEP 8: Style Guide for Python Code
https://peps.python.org/pep-0008/
PEP 257: Docstring Conventions
https://peps.python.org/pep-0257/
Subscribe to Mrs. Tech for programming explained step by step.
#Python #Programming #LearnToCode