I started out with programming with Mosch’s Python beginner’s course. I went about 1.5 hours into it, but I lost it. I think this is the kind of course that you have to take in one setting so that the concepts stay fresh in your mind. But I didn’t do that; I spread it out over several days and now I’m lost. I couldn’t follow along, so now I’m switching to another course which is by Bro Code – the 2024 free Python course. It’s a 12-hour course, so very very long. But yeah, I’ll try that and see what it’s like.
First of all, it starts by using PyCharm and he recommends that over VSCode because it is a little bit more beginner-friendly.
Here’s f-strings:
And so here continuing to focus on variables and values and f-strings:
# This is my first Python program (not really, but you know. also, it doesn't really seem like a "program")
print("I like BBQ chicken")
print("It's really good!")
# Variable = a container for a value (4 basic data types for values: string, integer, float, boolean)
# A variable behaves as if it was the value it contains
# strings
first_name = "Eberhardt"
email = "eberhardt87657@neberhardtestingrampm.com"
food = "BBQ chicken"
tarri = "676576"
# Integers (never put them in quotes, because that would turn them into strings. Inters are whole numbers that you can use in calculations.
age = 99
quantity = 1
num_of_students = 30
# Float (numbers that contain a decimal portion)
price = 10.99
pie = 3.14159
# Boolean (binary, either true or false)
is_student = True
is_rodent = False
print(f"Are you a rodent? {is_rodent}")
print(f"The price is ${price}.")
print(f"the number pie is {pie} + a lot more digits that i don't recall.")
print(f"You are {age} years old")
print(f"You are buying {quantity} {food}s")
print(f"Your class has {num_of_students} students")
print(first_name)
# you can also output this by using an f-string:
print(f"{first_name}")
# the cool thing about f-strings is that they make it easier to combine different variables and values
print(f"Hello {first_name}. How are you, today {first_name}? Do you know these kinds of people who tend to overuse your name, {first_name}?")
print(f"Hello {first_name}. Do you like {food}?")
print(email)
for_sale = False
if for_sale:
print("That item is for sale")
else:
print("That item is not for sale")
is_online = False
if is_online:
print("You are online")
else:
print("You are offline")
earth_flat = True
if earth_flat:
print("flat")
else:
print("round")
print(f"{first_name} is {age} years old and only remembers the digits {pie} of the number pie. He believes that the earth is {"flat" if earth_flat else "round"}.")
# Typecasting = the process of converting a variable from one data type to another
# str(), int(), float(), bool()
name = "uiygkuyg"
age = 117
gpa = 1.9
is_student = True
print(type(name))
# let's use the typecast function to convert our float into an integer:
gpa = int(gpa)
#now if we output this, it'll output only the decimal (it truncates the decimal)
print(gpa)
# let's use the typecast function to turn our integer into a floating point number
# age = float(age)
# print(age)
# let's now typecast our age to be a string
age = str(age)
print(age)
print(type(age) )
# remember that integers are numbers we can use in arithmetic expressions, but strings we can't
# let's typecast our name variable into a boolean
name = bool(name)
print(name)
Leave a Reply