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 - Type Conversion or Casting

bool()

see: Booleans

bool(1) # True
bool(0) # False

int()

Converts a value to an integer, when using it for a float it doesn't round the number up

x = int("10")  # Convert the string "10" to the integer 10
print(x)       # Displays : 10
print(type(x)) # Displays : <class 'int'>

int(9.555555) # 9

round()

Round a float to the next integer or the desired decimal if specified

round(9.555555) # 10
round(9.555555, 2) # 9.56

float()

Converts a value to a decimal number

y = float("3.14")  # Convert the string"3.14" to the decimal number 3.14
print(y)         # Displays : 3.14
print(type(y))   # Displays : <class 'float'>

str()

Converts a value to a string

y = str(3)       # Convert the integer 3 to the string "3"
print(y)         # Displays : 3
print(type(y))   # Displays : <class 'str'>

list()

Converts a value to a list

y =  list('hello') # Convert the string 'hello' to a list
print(y)           # Displays : ['h', 'e', 'l', 'l', 'o']
print(type(y))     # Displays : <class 'list'>

set()

my_set = set([1, 2, 3, 'hello']) # from a list
my_set = set((1, 2, 3, 'hello')) # from a tuple

Using with input()

input() returns a string, in order to use numeric operations on an user input you need to convert it first

age = int(input("Enter your age : "))  # Converts the input to an integer
print(age + 5) # Do a numeric operation

[!WARNING]

  • If an user input a value that cannot be converted to an integer or a float a ValueError will be raised
  • You must ALWAYS validate user input before trying to convert it
ยฉ 2024 d0z.eu | 0.1.0-beta.39