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 Variables


Python - Booleans

  • True
  • False
my_list = [1, 2]
if my_list
# is the same as:
if bool(my_list)

Casting

bool(1) # True
bool(-1) # True
bool(1j) # True

bool(0) # False
bool(0.0) # False
bool(0j) # False

bool('True') # True
bool('False') # True
bool(' ') # True
bool('') # False

bool([1, 2]) # True
bool([]) # False

bool({}) # False

bool(None) # False

Logic

see: Control Flow

nice_weather = False
have_umbrella = True

if not have_umbrella or nice_weather:
# if (not have_umbrella) or nice_weather:
  print('stay inside')
else:
  print('go outside') # executed

The above code prints go outside because not have_umbrella evaluates first (python reads booleans from left to right), and it seems working but if we flip the variables we get:

nice_weather = True
have_umbrella = False

if not have_umbrella or nice_weather:
  print('stay inside') # executed
else:
  print('go outside')

The code now prints stay inside which is wrong since nice_weather = True, to fix it we could do:

nice_weather = True
have_umbrella = False

if not (have_umbrella or nice_weather):
  print('stay inside')
else:
  print('go outside') # executed

or using and:

nice_weather = True
have_umbrella = False

if not have_umbrella and not nice_weather: 
# if (not have_umbrella) and (not nice_weather):
  print('stay inside')
else:
  print('go outside') # executed

but the most readable way would be to flip the statements:

nice_weather = True
have_umbrella = False

if have_umbrella or nice_weather:
  print('go outside') # executed
else:
  print('stay inside')
ยฉ 2024 d0z.eu | 0.1.0-beta.39