123 lines
2.8 KiB
Python
123 lines
2.8 KiB
Python
# doing some things.
|
|
x = 5.79
|
|
y = int(x)
|
|
print(y)
|
|
|
|
# printing length of str name with len() function
|
|
name = " Nik is big poop face "
|
|
print(len(name))
|
|
|
|
# finding and printing index 1 if str name as var z
|
|
z = name[1]
|
|
print(z)
|
|
|
|
# finding and printing index 2 through 5 of str name as var y
|
|
y = name[2:5]
|
|
print(y)
|
|
|
|
# replacing all "N" in str name with "P", after stripping blank space from the ends with var.strip()
|
|
name = name.replace("N", "P")
|
|
print(name.strip())
|
|
|
|
# {} is a placeholder, used for int age here
|
|
age = 36
|
|
txt = "My name is John, and I am {}"
|
|
print(txt.format(age))
|
|
|
|
# this is true, becuase int age is not empty (its an int, not nothing)
|
|
print(bool(age))
|
|
|
|
# this is false, because its an empty string (its nothing, not a string)
|
|
print(bool(""))
|
|
|
|
# defining list body_parts, seeing if str "arm" is present in it, printing "hooray" if it is
|
|
body_parts = ["arm", "leg"]
|
|
if "arm" in body_parts:
|
|
print("hooray")
|
|
|
|
### lists, bounded by [], can be modified. tuples, bounded by (), cannot.
|
|
|
|
# changing index 0 of list body_parts from "arm" to "pooper"
|
|
body_parts[0] = "pooper"
|
|
print(body_parts[0])
|
|
|
|
# appending "head" to list body_parts, then printing
|
|
body_parts.append("head")
|
|
print(body_parts)
|
|
|
|
# inserting str "butt" into index 3 of list body_parts
|
|
body_parts.insert(3, "butt")
|
|
print(body_parts)
|
|
|
|
# printing index -1 (the last one) of body_parts
|
|
print(body_parts[-1])
|
|
|
|
# defining set computer_parts, and list more_computer_parts
|
|
computer_parts = {"SSD", "CPU", "GPU"}
|
|
more_computer_parts = ["RAM", "HDD", "AIO"]
|
|
|
|
# updating computer_parts, with more_computer_parts, printing updated list
|
|
computer_parts.update(more_computer_parts)
|
|
print(computer_parts)
|
|
|
|
# defining dict Truck, and its values
|
|
Truck = {
|
|
"model" : "Ranger",
|
|
"year" : 2010,
|
|
"make" : "Ford",
|
|
"displacement" : 4.0,
|
|
"transmission" : 5,
|
|
"drivetrain" : "4x4"
|
|
}
|
|
|
|
# printing Trucks "displacement" value
|
|
print(Truck.get("displacement"))
|
|
|
|
# changing displacement value of dict Truck to 2.8, printing the changed value
|
|
Truck["displacement"] = 2.8
|
|
print(Truck.get("displacement"))
|
|
|
|
# setting a value, "color" in dict Truck, printing Truck's "color" value, the str "blue"
|
|
Truck["color"] = "blue"
|
|
print(Truck.get("color"))
|
|
|
|
# using the pop method to remove dict Truck's "transmission" value, printing the resulting dict
|
|
Truck.pop("transmission")
|
|
print(Truck)
|
|
|
|
# this line was typed on my thinkpad X395
|
|
|
|
X = 20
|
|
Y = 20
|
|
Z = 30
|
|
|
|
# logical operator stuff
|
|
if X == Y:
|
|
print("yes")
|
|
|
|
if X == Y and Y == Z:
|
|
print("yes")
|
|
|
|
# while i < 6, add 1. once it reaches 6, stop adding, and print ("")
|
|
i = 1
|
|
while i < 6:
|
|
print(i)
|
|
i += 1
|
|
else:
|
|
|
|
print("i is no longer less than 6")
|
|
|
|
# defining poopfunction
|
|
def poopfunction():
|
|
fruits = ["apple", "banana", "cherry", "Buthoal"]
|
|
for x in fruits:
|
|
if x == "apple":
|
|
print(x)
|
|
|
|
# calling poopfunction
|
|
poopfunction()
|
|
|
|
a = 2
|
|
lambda a : a
|
|
print(a)
|