Learning Python, Day 8 — Operators and Collections
I'm still annoyed by the disorganisation of this course. I am a pedantic creature, and by god, if you label something as a 1, 2 better be following it.
So I'm now going to do it based on what the actual structure is, not what comes up when I click "Continue".
Also, I'm wearing my Piccalilli HTML Programmer hoodie, so I am a programmer now, baby!
04 — Operators & 05 — Operators Examples
I did do Operators yesterday, but I rewatched it in order to remind me before I jumped into Operators Examples. Mostly because combining Arithmetic Operators and Assignment Operators is still confusing as hell to me. I still don't know what on earth //= would actually do.
Of course it turns out that, yep, the only one that can affect strings is +. So all my worries about how you use %= with strings were pointless, you only use it with integers and floats, so now it's just a generic "what on earth do you use modulo for anyway" question.
There has to be a better way to teach people that you can combine Arithmetic and Assignment Operators when you're working with integers and floats, but I can't quite figure it out.
I do like learning that I can check if strings are higher or lower alphabetically. And I do like the Logical Operators, because this is stuff I just remember doing in Excel for conditional formatting.
(Honestly, the amount of actual logical programming I did just to make a particular row or cell a slightly different colour...)
06 — Collections
I do like finding out that I can have lists within lists within lists within lists. Lists all the way down, people, everything carefully filed away. My hipdirectors list can sit within my directors list can sit within my crew list can sit within in my letterboxd list.
He said that you can't access items in a list at an index that doesn't exist. Does that mean that you can't have more than 9 items in a list? I'm going to have to figure that out.
Also, I've learned the word Tuple. Tuples are lists where you can't change the variables. I'm not 100% certain when you use them, but I'll probably learn more once I hit up the examples.
Dictionaries are good to know about, because lord knows I'll keep on assigning values to things, and ranges are interesting, but since it's number-focused, I'm not 100% sure I'll use it often.
07 — Lists
Yeaaaaaah boiiiii I'm bringing back my hipdirectors list. I don't care that the course is focusing on, like, the stuff you would carry in a game, I don't need Sword or Boots, I need David Cronenberg and Guillermo del Toro.
I do like that I can assign a variable to an item in a list if I know the index. So I can be like king = hipdirectors[1] and then every time I want to refer to The King...
hipdirectors = ["John Waters",
"David Lynch",
"David Cronenberg",
"Brandon Cronenberg",
"Ryan Coogler",
"Guillermo del Toro"]
king = hipdirectors[1]
print(king)
>> David Lynch
Yeah, you know it.
I also like seeing that you can pull the item that has the highest or lowest alphabetical placement using max and min. This will be great when you're trying to pull a list of names.
pop is going to be hard to remember, even though it's going to be the one I want to keep using, since it removes the last thing in a list.
And I did find that you can have more than 10 items in a list. I must have misheard him, probably talking about how you can't print something that isn't in the list, so print(list.[200]) doesn't work when you only have 189 items in your list.
Day 8 — Results
- You can only use
+or+=with strings. Everything else in Arithmetical Operators breaks. - You can find out if something is higher or lower in the alphabet by using
>and<with strings. - You can change items in a list, and you access them via index value.
- You can't change items in a tuple, and you access them via index value.
- Dictionaries store key-value pairs, and you access them via the key value.
- Ranges are lists of consecutive whole numbers.
- You can assign a variable to a specific item in a list by
variable = list[index number]. - You can count the number of items in a list by
len(list). - You can find the highest alphabetical item in a list by
max(list). - You can find the lowest alphabetical item by
min(list). - To add an item to the end of a list, it's just
list.append("item"). - To add an item into a particular list slot, it's
list.insert(index, "item"). - To remove an item at the end of the list, it's just
list.pop(). - To remove an item at a specific list slot, it's
list.remove("item"). - To empty the list,
list.clear()orlist = [].
I have a feeling that "multidimensional list examples", "tuples examples", and "dictionaries examples" should wait until Monday, because they're all going to hurt my head a bit. I had to keep jumping around as it was with the list examples, since there was even more information this time around. But I like that I can do a lot more with lists, even if it means I'm trying to think of hip directors when I'm half asleep.
Today's Sticker

A cosy little cactus cat under a blanket with her very own Mothman plushie from Eldritch Rach.