Foreground
Foreground
D0Z - motion / graphic / dev๐Ÿงบ

Brain ๐Ÿ”’

โœ•

brain

CAUTION

Some files are private or not ready yet, if a link gives you a 404 that's why :)
This is a work in progress, new notes will be added daily

List of note Indexes


                .... |\| .|||.    |\/|  .|\\. .|.
              .\\||/|.  .\|..||  .\|..|||...||.....
            .|   .....||.|\\\\\\    ... |\\\/. .\\. .||
        .\\|   .|\\|..|\\ .\\\\  .\\|. .\\\\\|  |\| |\\|
        |\\  |\\|..  /\\\. |\|\\   \\\\|.   .|\\. .\\\\|
        .\\. |\\\\\\\|.. .\\|      .\\||\\/|. |\\|     .|/\|
      \. .\\\||/\|....   \\| |\/   |\\\  |\\\| .\\|  \\| ....
    |\/  |\\| |\\\\\\\| |\|.\\\   \\\\. |\\\\| |\\  \\.  ||..
      ..|||\|  .. .\\\\. |\\\\\\  .\\|....|\\\. |\\\\\\  |/. |/
    \\\|..   .\\\ |\\. .\\\| \\|   |||\\\.  ...|\\/||.  .\\\
  |\|  |\/.  /\\\\\| .\\\\. \\.   .../|.   .|\\\|.   |\\\|  |\\
    .  |||\\|.  ..||| .\\|.  |\|  \\|..../\\| |\\|  .\\\\\   ..
    \\|  .||\|.|..      |\\\|./\  \\||\. ||...    .\\\\/.  |\/||
    ..|/||.   |\\\\\|.     .|/\|  ||.        .||\\\     .|||. |\
  .\/|  \\\. .|\\\|||\\\||..       .|\\\\\\\|\\\\.  /\\\\||. |
    .|| |\\\\|  .......|\\\\\\.  .\\\. ..|||....  .\\\\|.. ...
    \\||....|\\\\\\\\||\\\\\\\/   |\|....|||\\\\\\\/....|\\\|
      ||.|\||\\| .....|\\\\..\\|    .|\\\. ||........ .|\|...
          . |\  /\\/\\\\\\. |\.  .\\\\\\.  ./\\\\/  |\\\||.
        .|\.|\| .|\|... ..              ./\\|..|\\|  ..
            .|\\|  .\\\\.\\\\\\\   \||...\\\|..|\\\|.||
                |\. ..||....||     ... ..||\\\. .|.
                        ...            .......

โ†‘ Python


Python - Functions

Functions are blocks of code with a defined task. They allow better organisation, avoid repetition and provide better readability.

def function_name(param1, param2):
  # code to execute
  return value

function_name(arg1, arg2)

Parameters / arguments and return

  • parameters: variables that are passed to the function, they are defined in the declaration of the function.
  • arguments: values that are passed when calling the function.
  • return: the result sent back by the function after its execution, if not defined the function will return None by default.
def addition(a, b):
  return a + b

result = addition(3, 5)

Variables reach (scope)

The scope of a variable determines where it can be used, variables defined inside a function have a local scope, they can be accessed only inside this function.

Local scope

def my_function():
  x = 10 # local variable
  print(x)

my_function() # Displays 10
print(x) # Error: x is undefined

Global scope

x = 10 # global variable

def my_function():
  global x # mark that we want to use and edit the global variable
  x = 20
  print(x)

my_function() # Displays 20
print(x) # Displays 20 too because the global variable was edited

Default values for parameters

If you define a default value for a parameter and no argument is used when calling this function, the default value will be used instead.

def hello(word="world")
  print(f"Hello {word}!")

hello("Joe") # "Hello Joe!"
hello() # "Hello world!"
ยฉ 2024 d0z.eu | 0.1.0-beta.39