to learn to play the Ukulele. I've never played a strumming based instrument before. It struck me how many analogies to Python programming I've observed. Let's make learning Python like learning the Uke We will rely on analogies to playing the Ukulele...
typical le reading pattern for line in open("data.txt"): words = line.split() print(words) I will tell you that this code will do the following: 1. iterates over a le, then on each line 2. will break each line into words 3. print a list of the words found in step 2 Is it a good idea to teach Python this way...
you want to perform more complicated analyses. Read specially formatted les, perform analytical or numercial computations, access a database, generate a plot, ccreate a website ... etc numerical python -> numpy data science python -> pandas web development -> django visualization -> matplotlib bioinformatics -> biopython
With numpy how to select all numbers larger than x? # Generate numbers [ 1, 2, 3, ... 10 ] x = numpy.arange(10) # This is the selection pattern. y = x [ x > 5 ] This is called boolean indexing. You can use it before you fully understand how it works. You will make more progress if you start learning patterns from the beginning.
, G7 First I learned these without caring. I played songs with them. Then it go me thinking - why are these called the way they are. Why do they sound slightly differently.
got interested in learning more. Musical scales, tones, steps. Today I know that major chords are built out of: 1st, 3rd and 5th notes of the scale. So called seven chords contain the 1st, 3rd, 5th and 7th notes of the scale. The G chord represents the scale that starts on G . ... and so on ... I had more fun learning it this way as I already knew how to use the G chord
in open("data.txt"): words = line.split() print(words) It is fascinating how simple and how advanced even this simple example is. It encompasses everything that makes Python such an awesome language. By the end of the course you will understand that open is an iterator that yields a string class that has a split method that returns a list class .
but not overly generic. High utility - but not overly specialized. Integrates well into science and web development. There are hundreds of programming languages: Why Python? Python 's popularity -> survival of the ttest. Among the best languages to get things done quickly and ef ciently.
critically important. For writing "native" programs that need to integrate with an operating system closely. Writing programs that rely on GUI (graphical user interfaces). Possible to integrate other languages into Python . Example: C can be embedded into a Python program.
The Program: a le that contains Python instructions. Running The Program: having Python read and execute the le. Python programs have the .py extension (but are regular text les).
ensure that each is correct, then run the program. 2. Initiate a dialog with the computer, where you quickly execute and evaluate instructions, and iteratively nd the correct solution. Most people use a mixture of both, and you'll nd yourself attracted to one of the approaches. I prefer the second style.
links to the download. Alternatives: 1. Get Miniconda (a smaller version of Anaconda) 2. Of cial Python distribution If you already have miniconda keep using that.
web interface Inef cient ways to get started. They are the wrong kind of "easy". Promote a linear way of thinking You must learn to think iteratively - continuously re ne your ideas.
would be nice if it worked... It would be so convenient... Just type some commands and go. But programming is never a linear process. Interactivity does more harm that good - it slows down your understanding how programming is done.
objects. Within Python you can type: >>> help(str) prints: class str(object) | str(object='') -> str | str(bytes_or_buffer[, encoding[, errors]]) -> str | | Create a new string object from the given object. If encodin | errors is specified, then the object must expose a data buff | that will be decoded using the given encoding and error hand ...
le, running the code, repeating the process. It is essential to streamline that process as much as possible. Your editor should be able to: 1. Show you the number for each line in the le 2. Color code your instructions (helps recognize errors) 3. Execute your program with Python and show you the output.
. Write the following and save it as hello.py : print ("Hello World!") First task Set up your computer so that you can run this code right from your editor.
your computer set up. It is a one-time challenge - but can be very-very annoying: Where is my Python? Why won't it run my program? Why does this still not work? Persevere, ask around, Google it. Ask someone...
errors all the time If you are not making errors you can't be programming. Your skill is measured in how quickly you identify the source of your errors. Machines are stupid. Need babysitting
the program: print("Hello World!" print("Hello World!) print(Hello World!") Then rerun. What do you see? Are the errors the same? Are some errors more informative? Could you locate the error based on the message?