Create a simple Function
Creating user defined functions is at the core of computer programming. Functions enable code reuse and make code easier to develop and maintain.
basics of a user defined function
define a function with def
use indentation (4 spaces)
define parameters
optional parameters
return values (or none)
function scope (basics defaults)
def some_function():
use the def statement when creating a function
use a function name that starts with a letter or underscore (usually a lower-case letter)
function names can contain letters, numbers or underscores
parenthesis () follow the function name
a colon : follows the parenthesis
the code for the function is indented under the function definition (use 4 spaces for this course)
def some_function():
#code the function tasks indented here
The end of the function is denoted by returning to no indentation
Example
defines a function named say_hi
def say_hi():
print("Hello there!")
print("goodbye")
define three_three
def three_three():
print(33)
In questa pagina del sito puoi guardare il video online Simple Functions - Introduction to Python: Absolute Beginner Module 2 Video 2 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Book Simplifiers 03 agosto 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 40 volte e gli è piaciuto 2 spettatori. Buona visione!