Intro to Python
I’m going to start with a statement and a story:
I hate python.
When I was in the 10th grade the math class was geometry. The chapter of logic came along and it was the first time I actually had to study (this is not a brag, I did not get good grades but I would’ve actually failed without studying). You had to study the logic to be able to compete the proofs. It sucked. But once I got it, it was cool. You know, try hard + get good grade = feel of accomplishment. That’s what python is. One big logic bomb (so far). And I hate it, don’t forget about that.
So I completed the first 2 chapters of the intro to python course awhile ago. Today, that’s all I got through again. All the answers were already there so I essentially just read through the slides & work to jog the memory. I then took a practice quiz of those 2 chapters. 5 questions. I went 2/5. Abysmal. The memory was not jogged to say the least.
Anyways…onto what I ‘learned’…
Python is a free open source workspace essentially. This course is just like it. Feels like there is no direction. I don’t know if this is in the real python as well but you print( ) line items in script.py and the answers shoot out in IPython shell. They’re stacked on top of each other in this course. However, you can just do work in the Python shell to check work work then print it above which then…shoots it out below again? I don’t really know. All confusing. To submit your work, you print in the top script.py
Variables are big in python. A variable is something you assign a value to. You assign a value using the equals sign.
height = 5 | Now if you go to print height you can code it as ‘print(height)’ and it will return as ‘5’
You can do math in python.
print(3+4)…this returns 7
However, you can also add strings (letters/words). This mashes the words together. print( str + ing)…returns string
There are also lists
For example you have a house that has rooms with square footage lets say:
Hall = 11.25 | kit = 18.0 | liv = 20.0 | bed = 10.75 | bath = 9.50
areas = [hall,kit,liv,bed,bath]
print(areas)…this will return a list of the measurements now. ‘areas’ is your list
There are now also lists of lists (you see where the logic story comes into play now, right?)
Let’s say you wanted to formally name all the rooms above ‘hall’ as ‘hallway’, etc.
You can now make a list called ‘house’ and it would look like this:
house = [[‘hallway’, hall]
[‘kitchen’, kit] (and so on below until you get to the last list of the list)
[‘bathroom’, bath]]
Now you can return ‘house' which is written print(house) and will return as this:
[['hallway', 11.25], ['kitchen', 18.0], ['living room', 20.0], ['bedroom', 10.75], ['bathroom', 9.5]]
When subsetting lists (numbering them) the list starts at 0. Example below:
areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50]
print(areas[1]) | print(areas[9]) | print(areas[5]) returns 11.25 | 9.5 | 20.0
11.25 is the 2nd item in that list but because hallway is 0, 11.25 is 1.
List slicing
areas [1:4] returns: 11.25, kitchen, 18.0
the first number of that, 1, is inclusive while the lsat number, 4, is exclusive. So it returns the 3 values above
Addition, + sign, of a list will make said list now longer
del ( ) will delete items from lists
This probably reads as gibberish. Writing it felt like gibberish. I’m hoping python comes together for me at some point. I am out in left field beyond belief. This is not fun. I also hate it.
Day 4…complete.
-TJ
To be continued…….