Let's get started! 🔥🔥🔥 In this video, we will write a few PYTHON 🐍 scripts to demonstrate how to define and use functions ♻️. In the examples, we define a simple function then 📱 call the function, accept one to more input parameters in a function, and accept an optional input parameter in a function. In this tutorial, you will learn some basics in less than 10 minutes!
In this video, you will learn how to:
★ 0:09 When to use a function?
★ 0:20 Create a function
★ 1:31 Create a function that accepts an input parameter
★ 3:01 Create a function that accepts an optional input parameter
★ 4:10 Create a function that accepts multiple input parameters
Tips and Tricks:
► Functions help encapsulate functionality in one place, compose your program, update your code, and add new features. Create a function to:
• Keep your program understandable: Each function should contain a single task or responsibility. Keeping functions short and focused helps.
• Keep your program manageable: Using a good name for each function.
• Keep your program more easily written: Call functions as needed from a main function in your app's logic.
• Keep parts of your program reusable: Use the function multiple times, and update it in one spot.
► A function contains five parts:
1. The def keyword.
2. A function name.
3. A pair of parentheses symbols (()) with input parameters are defined within them.
4. A colon symbol (:) to end the function's signature.
5. A code block below the signature, which is the body of the function that runs when the function is called.
► Make an input parameter optional by supplying a default value that is used if the caller doesn't pass an argument.
► Each pair of parameters can be separated with a comma symbol (,).
► The value None can be used when defining the default value for an input parameter.
► None is the perfect way to represent a value that doesn't exist.
WANT MORE PYTHON TUTORIALS?
🐍 Python Coding for Beginners:
• 🐍 Python Coding for Beginners
For the setup, please read the followings before you begin:
1. Download latest Python: https://www.python.org/downloads/
2. Install Python and remember to select "Add Python... to PATH" when asked.
3. Download and install latest Visual Studio Code: https://code.visualstudio.com/Download
4. Install the Python extension for Visual Studio Code: Go to View and select Extensions, or select the Extensions icon, then search for python.
Python - a programming language used by world-class companies such as Amazon.com, Alphabet (Google), Facebook, Twitter, and NASA.
👇 SUBSCRIBE TO CODING WITH KIDS 👨🏻💻👩🏻💻 YOUTUBE CHANNEL NOW 👇
/ @codingwithkids
#CodingWithKids #PythonProgramming #PythonForBeginners
Sur cette page du site, vous pouvez voir la vidéo en ligne How to Code PYTHON: *Create Functions in Python* durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Coding With Kids 20 janvier 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 160 fois et il a aimé 6 téléspectateurs. Bon visionnage!