Going to Learn Python Now : Pt. 4

Superhematoma_illustration_ensemble
When not learning Python, I’ve been playing lots of FTL, (totally beat it on Easy) and I’ve also been working on some artwork for Super Hematoma. You should click that there link if you want to learn more about the image that’s up above…

But you’re here because you can’t get enough of my notes that I take while learning python right? So without further ado, here we goooo!

Exercise 19: Functions And Variables

  • -this doesn’t seem to be anything new to me
  • -it does seem like bad practice to use variable names multiple times for different things though.

Exercise 20: Functions and Files

  • -A file in Python is kind of like an old VHS. It has a “read head,” and you can “seek” this read head around the file to positions, then work with it there. Each time you do f.seek(0) you’re moving to the start of the file. Each time you do f.readline() you’re reading a line from the file, and moving the read head to right after the n that ends that file.
  • -None of the other concepts here seem extraordinary

Exercise 21: Functions Can Return Something

  • -functions within functions within functions within functions isn’t new territory for me either. Have had to do this sort of witchcraft a few times in my HScript days. I’m following this no problemo

Exercise 22: What Do You Know So Far?

  • -yyyyeah, so this one basically just asks you to review that you’ve learned so far.
  • –Consider this blog the review 🙂
  • –Largely, I’m doing this so that I’ve got my notes available no matter what computer I’m at in the future.

Exercise 23: Read Some Code

  • -I’m kind of bad when it comes to assignments of the completely random variety. I haven’t had any difficulty with what I’ve learned so far, and have been able to follow along at a pretty quick pace.
  • -At this point, I’m going to take the arrogant approach, and just move on

Exercise 24: More Practice

  • -this is just a practice in typing, really. But it does help cement the stuff that we’ve done so far into long-term memory

Exercise 25: Even More Practice

  • -here we’ve got some new stuff… interacting with a py file from the interpeter!
  • -we’ve got split() which parses a string and returns a list of words as a list
  • -we’ve got sorted() which takes a list of strings and seems to return it organized alphabetically
  • -when we popped the words off the stack using the pop() function, we full on remove it from the list. printing the words list again no longer includes either the first or last words once we’ve popped them.
  • -I was thrown off here for a moment, as I didn’t notice that the author was running the print_first_word function on different lists of words.
  • -Oh… hey! neat:

    Try doing this: help(ex25) and also help(ex25.break_words). Notice how you get help for your module, and how the help is those odd “”” strings you put after each function in ex25? Those special strings are called documentation comments

  • -Also news to me:

    Typing ex25. is annoying. A shortcut is to do your import like this: from ex25 import * which is like saying, “Import everything from ex25.” Programmers like saying things backward. Start a new session and see how all your functions are right there.

 

And I think I’m going to cut it there for the night. I will say, I like http://learnpythonthehardway.org/book/. The writing is somewhat humerous, and it’s keeping my attention. I don’t know if my mind is just more open this time around or what, but I feel more interested in sticking with it than when I attempted dive into python a few years back.