🐍 LEARN PYTHON WITH 250+ EXERCISES:
👉 https://www.commentcoder.com/api/go/?...
🐍 Learn to program in Python with this new series in French for beginners - Part 4: How to code your own functions? And a fourth project! 🚀 Want to learn to code but don't know where to start? Then you're in luck… Python is one of the best languages for learning to code! In this Python tutorial in French 🇫🇷, you'll learn everything you need to know to learn Python.
⏭️ Part 5: • Tuple, Set et Dictionnaire en Python
⏮️ Part 3 (if you missed it): • Comment utiliser les Boucles en Python ?
👨💻 Link to the GitHub for the code: https://github.com/commentcoder/appre...
With Python, you can:
• Program AI (Machine Learning)
• Automate your daily tasks
• Create websites (backend)
• Do Data Science
• Coding Video Games
🐣 You don't need any coding experience to follow this tutorial.
⛰️ We'll start from the basics and work our way up together.
Table of Contents:
00:00 - Introduction
00:26 - Function Declaration
01:31 - Positional Parameters
02:12 - Default Parameters
02:45 - args and kwargs
03:50 - Return
05:10 - Scope
06:37 - Summary
07:09 - Fourth Project!
In this video, we'll cover creating custom functions to organize and reuse code in complex programs.
Segmenting code into subroutines, called functions, is essential for maintaining clarity and facilitating code reuse.
We've already used native Python functions such as `print` and `input`. Now, let's create our own functions.
To declare a function, use the keyword `def`, followed by the function name and parentheses for the parameters.
Let's create a function called "my_bottom_bar_function" and add a variable declaration and a `print` statement inside it.
To call the function, simply use its name followed by parentheses, for example, `my_function()`.
Functions can take parameters. Add them between the parentheses during the declaration. You can also define default values to make them optional.
A function can receive an unlimited number of parameters with `*args` for positional arguments and `**kwargs` for named arguments.
Functions can also return values with the keyword `return`. You can return multiple values simultaneously.
Variable scope is important. Variables declared within a function are local and are not accessible outside of that function unless declared as global.
Now let's move on to a practical project: creating a simplified version of the `range` function. The `simple_range(n)` function will return a list of numbers from 0 to `n - 1`.
Try implementing this function yourself, then come back to see our solution.
```python
def simple_range(n):
L = []
i = 0
while i less than n:
L.append(i)
i += 1
return L
print(simple_range(5))
```
Feel free to improve this function by adding features from Python's native `range` function.
Don't forget to like the video and subscribe to stay informed about the rest of the tutorial.
#python #training #programming #developer #learntocode