Extensions
Basic String Manipulation & and/or
More on Modulo
test1 = 12 % 2 # this will equal 0 as 2 divides 12 exactly
test2 = 13 % 2 # this will return 1 as 13 = (6 * 2) + 1
# We can use this to check if something is even or odd!
number = 10
if (number % 2) == 0:
print("Number divisible by 2. That means it's even!")
else:
print("How odd ¯\_(ツ)_/¯")More Logic with and & or
# Use in declaration
try_and1 = (7 > 6) and ("hi" != "bye") # will be true
try_and2 = (6 > 7) and ("hi" != "bye") # will be false
try_or = (6 < 7) or ("hi" != "bye") # will be true!
# Use in comparison
is_scary = False
has_scales = True
if has_scales and is_scary:
print("GODZILLA!!! \0/ \0/ \0/")
elif has_scales or is_scary: # one or the other, as "and" wasn't true
print("Get it away from me!")
else:
print("How boring...")Sub-component checking with in
Putting it all together
Last updated
Was this helpful?