-
Notifications
You must be signed in to change notification settings - Fork 0
Python
Axolotl edited this page Jul 14, 2025
·
1 revision
Python is a programming language.
# This is a python program!
print("Hello, World!")
foo = 1 # You can do this
foo = foo + 1 # And this
foo = "OMAGAWD" # Oh yeah, and this
foo = [1, 2 , "OMAGAWD", [1]] # List: mutable, ordered, ANY values, variable length
foo = (1, 2, "OMAGAWD", [1, 2, "OMAGAWD"]) # Tuple: imutable, ordered, ANY values
foo = {1, 2, "OMAGAWD", [1, 2, "OMAGAWD"], a} # Set: imutable items but can add and remove, unordered, ANY values, variable length
foo = {"a":foo, "b":2, "L Bozo":"somebody somewhere named Calvin"} # Dictionary: mutable, ordered, access ANY values with keys, variable length
if "Calvin" in foo["L Bozo"]:
print(foo["L Bozo" + " is L Bozo") # Yeah, we use whitespace. Deal with it. Not pictured: elif, else (if will always be true), ur mom (wouldn't fit)
try:
print(foo[""]) # That's not a key that exists in foo
except(KeyError):
print("Uh-oh") # You can also use plain except. This specifically handles KeyError exceptions
else: # If no exception was caught:
raise Exception("impossible state") # Throw an error
match foo["b"]: # Do stuff based on the falue of foo["b"]
case 1: # basically if foo["b"] == 1
print("B1")
case 3|4|5: # any of 3, 4 or 5
print("B is smol")
case _ if foo["b"] > 5 # Otherwise if it's more than five
print("B is thicc")
case _ if foo["b"] % 2 != 0 # Otherwise if it's odd
print("B is weird")
case _: # Otherwise
print("Dang, I've outsmarted me. What was it?")
print(foo["b"]) # Yes, you can print integers. As long as it has a __str__(self).
print("Oh.")
f = 1.3 # Oh, look; a float!
b = True # Wow, a bool
nb = False # ANOTHER BOOL WHOA