Support: 1-800-961-4454
Sales Chat
1-800-961-2888

How I Started Learning Python

37

Disclaimer: If you already know Python really well, this post might not be handy for you. However, I’d still love to see your comments and feedback if you have a moment to reply.

Much of my recent work has centered on OpenStack and I’ve found myself overwhelmed by learning Python. Although I don’t have any formal education on anything related to computer science or programming, I’ve worked my way through PHP, Perl and Ruby.

Ruby seems to be the most comfortable language for me to use due to the simplicity of the syntax and the handy features provided by the standard libraries and common gems. Python always caught me as strange due to the forced indenting (I indent my code properly anyway, but it still feels weird to be forced to do so), module namespaces and the overall syntax. Things like list and generator comprehension made my head spin and I avoided Python like the plague.

All of that had to change over the past few months. I’m not an expert in Python by any means but I’ll be glad to share with you how I trekked from the depths of Ruby to the edge of Python.

Learn Python The Hard Way

Zed Shaw’s guide to learning Python has been the primary recommendation from every Python developer I’ve polled at Rackspace. It is clear, concise and accurate; however, I never did finish the HTML guide. Something would end up distracting me or I’d become discouraged by something I couldn’t understand.

That’s when I found the video course on Udemy. The video course costs $29 and comes with the PDF copy of the book. You can watch Zed work through the problems on screen via an easy-to-follow screencast. He even makes common errors on screen and runs the interpreter so you can get familiar with exceptions from common typos.

Python Documentation

If it’s in Python or the standard libraries bundled along with it, it’s in the Python documentation. There are plenty of code examples for almost all of the methods from the standard libraries on the site. It’s a good resource to bookmark while you’re learning what certain methods do and which parameters they expect. You can also ensure that your code isn’t importing modules that are deprecated.

Stack Overflow

This could draw criticism from some, but Stack Overflow is a good resource to find better ways to do things in Python. I’ve written some pretty ugly Python code only to find that I could have called a couple of methods from modules found in Python’s standard libraries. You can find lots of examples of code simplification and recommendations for which modules to use for a particular project.

Keep in mind that some suggestions on the site can be subpar. Some may contain deprecated or insecure code that could hurt your project’s success. Be sure to look through the comments after each answer to ensure that you’re reading a solid solution.

Coworkers And Colleagues

Some of the best resources for learning Python are probably all around you in your office or online. I’m extremely fortunate to be surrounded by gifted and experienced developers at Rackspace who genuinely care about their work and want to share their strategies with others. I’ve always had a tough time understanding lambdas (I couldn’t understand them in Ruby, either), but one of my coworkers took me through some examples as I was leaving work.

If you feel like you might be a bother to your coworkers, try to do some homework on the topic first or give them a specific example of what you’re trying to solve. It will show them that you’ve done your best to understand the topic but that you need some help getting over the hump. A hot cup of their favorite coffee or snack doesn’t hurt either.

Just Try It

Find a problem, make a project and write some Python. Most of us have something we’d like to accomplish if we had the time. Take that idea or problem and write Python to solve it. You’ll pick up new knowledge as you work through the project and you’ll probably back yourself into a corner more than once. When it happens, go back to the documentation, do some Googling and lean on your peers.

I’ve been working with Python for just over a month and these strategies have jump started my learning by leaps and bounds. If you’re struggling, drop me a line and I’ll see what I can do to help. I’m also eager to hear your strategies for learning Python so they can be shared with others.

About the Author

This is a post written and contributed by Major Hayden.

Major Hayden is Chief Security Architect and a Linux engineer who has experience working on large-scale OpenStack deployments and automation in Rackspace Cloud. He enjoys writing posts about Linux system administration and security on the Rackspace blog as well as his personal blog.

Follow Major on Twitter @majorhayden.


More
37 Comments

Congrats on getting started with Python. Like with Ruby, you know have access to a multitude of well-crafted libraries. Whether it’s machine learning (pybrain, scikit-learn), NLP (NLTK), scientific computing (scipy), numeric computing (numpy), statistics (pandas), etc. And in spite of any initial difficulties you might have, I’d highly recommend list comprehensions — once you learn them, they are easy to write and read, and you sometimes you get better performance. Iterators are extremely handy, as are generators, and generator comprehensions. You can make pipelines with them, just like unix-style pipelines! For a good introduction to generators targeted at systems programmers, see: http://www.dabeaz.com/generators/

PS: Impressed you know Perl! I never managed to feel comfortable with it.

avatar Eric S. Bullington on April 11, 2012 | Reply

Saw this posted to the Rackspace twitter feed and really enjoyed it! I’ve had so many people ask me in the last three days, after hearing I’ve got a development background, if I know python. I was already determined to at least become familiar with the basics and write a “hello world” program to get me exposed to some of the lingo. This is a GREAT place to start and I don’t have to bug you guys (yet!) Have a great night!

avatar Rainya Mosher on April 11, 2012 | Reply

here’s another resource I think is quite useful … https://developers.google.com/edu/python/set-up

avatar alex on March 28, 2013 | Reply

Just use C++ Builder, its so easy a child could do it.

avatar Mike on March 29, 2013 | Reply

For compact loopless code use “J” from jsoftware.com it is free, it is powerful. It is very portable.

avatar Fred Mellem on March 30, 2013 | Reply

I started learning Python on codecademy.com The simple step-by-step tutorials are pretty neat way to get started coding.

avatar Pete on March 30, 2013 | Reply

Would be very interested to know if you have thoughts on the comparisons of Ruby to Python frameworks – mostly Rails v. Django.

avatar 504SpyBoy on April 6, 2013 | Reply

Try CS101 at Udacity.com along with follow up courses in their sequence. Free, online and pretty effective pedagogically.

avatar Charlie on April 12, 2013 | Reply

I like Udacity for learning Python as well. Good suggestion.

avatar Shannon on August 8, 2013

Regarding coworkers and colleagues, they can be GREAT resource for learning to use computers. When Microsoft Windows 95 and Office 95 came out, nobody in my work group took classes on that software: We learned as we went and helped each other. In a group of 20-40 people, someone is likely to know a trick or two that helps you solve your problem. Taking a class on a programming language is a good way to get a jump start, but in the end sharing knowledge with others in your group of friends and colleagues is still a good way to build skills.

I’m in the process of learning Python, too, since it is available for free on most popular operating systems, the code is portable, and it’s truly a high-level language. Not only can I use it for my personal computation needs, it is gaining ground as a CGI language on the Web, gradually replacing PERL.

avatar Gunnar Wolpe on April 16, 2013 | Reply

My grade-schoolers are fortunate enough to have a school that has computer class as part of their curriculum. Unfortunately, I have never heard of any coding-related projects take place even at the upper grade-level.

I came across a book about Python called, “Hello World! Computer Programming for kids and other beginners” by Warren and Carter Sande. It’s essentially a series of lessons and comes with free (with book purchase) electronic supplemental material. I tried a few lessons in the book at home which the kids seemed to like, but admittedly doing the lessons at home got lost in the shuffle of our daily schedules. With summer break approaching I plan to pick it up again with the kids. I have no affiliation with the authors or publisher–just a parent that realizes the benefits of kids acquiring coding skills. I plan to also take a look at the resources noted in this article and related comments.

For those that don’t already know, having coding skills helps people in many more ways than just creating code. I hope coding in school curricula becomes more mainstream given all the potential benefits to the students and the community at-large.

avatar Python Newbie on April 20, 2013 | Reply

What are the broader benefits of coding. as opposed to, perhaps. learning a musical instrument or how to draw? or another human language ?

Some folks also are dealing with schools that lack books, libraries and teachers, let alone computers and coding classes, but i’m sure that the NSA wont let any potential talent go to waste.

avatar zak on July 8, 2013

Since a good portion of the world runs on computers, knowing how to program, or at least understanding programming concepts, lets you better understand and have control of the devices around you.

avatar ThisDesignUp on October 11, 2013

What a snarky juvenile remark. Students that lack any disciplined programming experience have poor logic processing abilities, have difficulty decomposing even simple problems into their component subproblems then solving those in the proper order…this is NOT programming … this is problem solving which in many way programming is the language of digital problem-solving. Programming also leaves a record of what one has done, their approach to a problem. Try that with pulling down menus and pushing “buttons”.
Some programming of some sort should be taught in the upper levels of high school…students who avoid programming, math, etc can not make up for those with so-called “people skills” they will still be missing a huge chunk of useful knowledge and work ethic habits the serve one well in the real world of employment as well as personal life.

avatar bobruark on October 28, 2013

Why again would I want a, “skill,” that someone else can learn in a month as you have in this article and compete against me for employer dollars? Such a thing doesn’t seem very specialized nor highly compensatable to me, thus not worthy of my interest nor time investment. I’m happy for your progress and glad that you’ve found something interesting, but for myself well, give me something more challenging than Python.

avatar Frank Skinner on May 11, 2013 | Reply

You can learn to use a hammer in five minutes. If it’s that easy, why should anyone get paid for using a hammer or bother to learn it, right?

avatar B.F. Skinner on July 5, 2013

It’s one thing to learn something, and another to master it.

avatar Scott on August 5, 2013

Learning is one thing – mastering is another. To me learning is working towards understanding the fundamentals in any language, how it fits in with technology, it’s abilities as well as limitations.

avatar Incipio01 on September 25, 2013

This person was paid to learn Python. They were able to make the learning of it into a technology assignment for rackspace. The ordinary person out there has many distractions and motivations or lack thereof. The author was motivated to reach a level of competence that allowed for a write up; his skill is not necessarily an indicator that opportunity costs of learning Python are high.

avatar SW6 on October 19, 2013

What an arrogant BS remark to justify your laziness. Typical, you could say that about just about anything. So I guess society really has no real need for you. Will you then just go away or just apply for “assistance” for somebody else can take care of you.

avatar bobruark on October 28, 2013

Go to http://www.coursera.org and take the basic python course through Rice University taught by Joe Warren and Scott Rixner. It is a great course for beginners and it’s free. It takes nine weeks to complete. I went from having zero programming experience to being able to program basic programs over that time. The final project was to program a game of Asteroids. Memory, Black Jack and Pong were also games we had to program ourselves after finishing the lectures.

Great course, I recommend it highly for people with no programming experience.

avatar Wayne on June 19, 2013 | Reply

I have been using Python for a few years. I’m fluent in quite a few programming languages, but Python is by far my favorite. The attraction to Python and the most compelling reasons to learn it result from a few core features: Code to solve your particular problem tends to be concise and relatively easy to maintain and extend. In Python (well written) code is usually quite easy to read an understand. (Compare that to Perl!)

As noted above, there are modules available to address almost any problem domain, with excellent resources for AI/Machine learning, natural language processing, advanced Network programming, image processing, game creation, you-name-it.

Even though learning Python isn’t hard, and getting a good working understanding is often reported in just a few days, the answer to the question of why learning something that is so easy constitutes a ‘valuable skill’ is that Python will make you more productive in whatever skills you bring to the table (even if those skills are some other languages like Java or C/C++). Python plays nicely with others, at least some others.

Try it. You’ll like it.

avatar Dan on July 5, 2013 | Reply

I learned Python through being alerted to its existence by one of my students (I teach at the college level), and deciding to try it. I got a few books (mostly dealing with Python 2.x; I still have not done much with Version 3) and played around a bit.

Then I was assigned a Numerical Analysis course, which is best taught in conjunction with a programming language, and I gave a few programming assignments to students in that course. In this context, the functional-analysis aspects of Python were very useful. So, to write a routine that will find a root of a given function by the method of bisection, you merely pass to the routine the name of the function, and the endpoints “low” and “high” of the range where the root exists.

Testing out this simple routine (and others like it) was made much simpler by the use of lambdas. And, as others have said, there is a huge range of freely available packages. Want more precision? There’s Decimal and mpmath. Want to see if there’s a faster way to find a numerical value (or save yourself the work of writing the code yourself)? There’s NumPy and SciPy.

I have also downloaded some games from PyGame. I have considered letting a colleague who teaches astronomy know about PyEphem and astropy. There’s biopython and pysb for biologists, and a staggering number of others.

Now, for my own research, I am looking into extending and building upon a Python package called igraph, for networks and abstract graphs. From where I sit, this language is a cornucopia.

avatar JCG on July 9, 2013 | Reply

The best getting started resources are the tutorials linked off the Python documentation page. As far as books so, I am partial to the “Python Essential Reference” by David M. Beazley. When you’re learning use the python interpreter for ad hoc explorations. It’s faster to figure out syntax by typing at the interpreter than it is by writing programs.

Python is very similar to Ruby. If you know one the transition to the other should be easy. In particular Python’s for-comprehensions are the same thing as Ruby’s chains of anonymous functions.

http://www.python.org/doc/

avatar W.P. McNeill on July 11, 2013 | Reply

Python is an incredibly versatile language and is a deadly art if you can learn it well. Highly recommend to anyone looking at the language to dive in and learn it — I’ve recommended it to many people over the years and its been extremely valuable to each of them.

avatar Ryan May on July 19, 2013 | Reply

Agree with most of the positive comments.

One big caveat: Python still doesn’t play well with the Windows file system. Many of the examples you’ll find online are for Linux systems and can’t be directly used with Windows. You can bump into some serious problems when Python tries to interpret the backslash as an escape sequence! There are workarounds, but sometimes the workarounds don’t work.

avatar polistra on July 29, 2013 | Reply

I believe the trap comes from the difference between “\” and “\\”. A Windows dev thinks that “\” is fine for just about all occasions. A *nix dev knows that a “\” is just an opening gun while “\\” is a back-slash.

Python allows quick-and-dirty path references but provides “os.sep” and “os.path” for safe-and-sane coding.
http://docs.python.org/2/library/os.html?highlight=os.sep#os.sep
http://docs.python.org/2/library/os.path.html

avatar Ted K. on July 30, 2013

nobody plays well with windows systems all the time

avatar bobruark on October 28, 2013

Great ideas, I started taking a course on coursera that taught matrix algebra using python, I had to drop it due to work but in the first few weeks I managed to learn a lot about comprehensions and lists and functions, and being forced to do exercises helps you solve the problems – maybe this helps others

avatar Mario seal on August 6, 2013 | Reply

Great blog! I am wanting to learn python, but have no programming skills. I started reading some books on Python but reading alone doesn’t really help you learn. I guess you just got to learn by doing it.

avatar Darren on August 9, 2013 | Reply

here’s another great resource.. http://www.pythonforbeginners.com/

avatar luke on August 31, 2013 | Reply

Still i coule NOT understand what IS python and for what purpose itis.

avatar AHMAD MADI on September 6, 2013 | Reply

I’m with you, Ahmad – what the heck is Python?

avatar Cranios on September 23, 2013

I was really expecting a story about snakes, but found it interesting regardless. The only coding I ever learned was D Base V and was in the midst of a self created project of doing an application of building a data base with query abilities to access data on Zoning files that is still kept on index cards dating back to 1923 when the City adopted it’s first Zoning Ordinnance. Iwas in the proces of entering the final dara card by card, when my job assignment changed and the person that replaced me had no programing ability whatsoever but as hard as I tried to explain to her that the remainfer of the project was simple data entry, she could not grasp it and the Directoer decided the Department would abandon the existing work. I was crushed but since I was making considerably more per hour, I just rolled with it and moved on.

avatar Steve H. on September 23, 2013 | Reply

Nice to see a fellow Pythoner. It’s good to see people using Python a lot. I started using Python a lot and most of the times felt at ease , due to one thing: The video tutorials from CBT. They have got everything, starting from PHP, RUBY, PERL, BASH, PYTHON etc and the best thing you can download them easily from torrent. Till to date those tutorials in collaboration with StackOverflow had been the best thing to happen to me .

avatar Kunal Bhowmick on September 27, 2013 | Reply

I would agree on jumping into documentation and justing trying it. Consuming APIs and utilizing other tools and libraries are one thing, however at some point you will desire to nose dive deeper, which is currently where I sit. My current to do list is pythonthehardway, Google Class 4 day deep dive, and finally pythonmonk.

cheers!

avatar Andrew on September 30, 2013 | Reply

This is great. I’m just beginning an engineering degree and one of the biggest holes in my background knowledge is my complete lack of any programming skills. I’ve been trying to use MIT’s Open Courseware program for introductory programming, which teaches Python, but I just don’t have the time to essentially do a whole other class on my own time. It’s a great resource, but it’s very comprehensive and I just need something to give me the basics in a short time. Looks like the resources you’ve linked to here might be more along the lines of what I need.

avatar Poodles McGee on October 1, 2013 | Reply

Leave a New Comment

(Required)


Racker Powered
©2014 Rackspace, US Inc.