Moving On With Python Notes

Here are some steps that greg sent to help us continue to learn Python, and actually create something! Check it out:

“As for next steps with Python, I think you should definitely stay with Learn Python the Hard Way (or some other introduction; you might be able to find a good online course somewhere like Coursera) for the moment. There are still some pretty fundamental concepts that you need to know that I wasn’t able to introduce in the course. Here they are, most important ones first:
Conditional branching: How do you make your code do one thing given some input and a different thing given a different input. Some really important topics you’ll see are if/else statements and while loops.
Other data structures: I’d only shown you variables and strings, but there are a whole bunch of other valuable data structures available. In particular, you’ll want to learn about arrays (which Python calls lists), linked lists (which don’t exist in Python), and hash tables (which Python calls dictionaries).
Functions and modularity: So far we’ve been putting all of our code into one big script. That works for really small things, but once you start doing more complicated things you’ll want to be able to reuse parts of your code. You can group parts of your code into functions and then call those functions from the rest of your code – this means that you only have to write the code for the functions in one place. It also means that you can easily reuse code that you wrote for one part of a project when you’re working on a different part (this is called modularity and it is awesome).
Algorithmic efficiency: There are always a bunch of different ways that you could solve a problem with code. Some of them will take a lot longer to run, though. The basic question of algorithmic efficiency is this: what is the relationship between the size of my input (ie. the number of bytes in the input file, the number of elements in the list/array/hash table, the number of people using the system) and the amount of time it takes for my program to run. Put another way, you could ask the question “If I double the size of my input, how much longer will it take for my program to run?” – you might think that it should take twice as long, but that won’t always be the case. There are some algorithms that would take the same amount of time (like finding the length of an array) or that might take 4 times as long (like calculating a multiplication table of all the numbers up to n).
Exceptions: Most languages give you the option of having your code completely stop when some thing goes particularly wrong. For example, you all were getting RuntimeErrors when you would try and read from an empty StdIn. Turns out you can tell Python that there are other times that your code should raise certain types of errors (for example, you might want to prevent somebody from saying that they had a negative number of quarters).
Objects and classes: This is a branch of programming called Object Oriented Programming, and you should only move on to this once you’re comfortable with the other parts. The basic idea is that most of the time, your code isn’t just pushing numbers around. Usually you’re trying to model some real-world behavior, and in the real world we think of things in terms of objects (ie. I am typing on a computer, I drive a car, I eat a meal). Classes allow you to define a particular type of object and the things it can do. For example, you might define a Car class that has wheels, a brand name, a color, a top speed, a fuel efficiency, etc. You could then create a bunch of different Car objects and have them interact.
Once you’ve seen those concepts (I won’t say mastered those concepts since you won’t master them until you’ve applied them to an actual project), you’ll be ready to try applying them to a project. I would say that http://www.instructables.com/ is probably a good way to come up with project ideas; also just be on the lookout for things in your life that you could make easier with some automation. It may be easier to come up with feasible projects if you’re working in JavaScript, since then you can make a web app without having to learn a specific web app framework (which you’ll have to do if you want to work with Python).
Keep me posted on the projects you come up with. I’ll be interested to see what you make!
Greg”
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s