Learning Python is like learning a spoken language — I thought.

Image by: Mary Pahlke

I have learned both Spanish and French with various approaches:

-Guided and Unguided — “Guided” practice is learning in the classroom or from Rosetta Stone. “Unguided” practice refers to trying to negotiate rent, understand my Master’s material, and even make friends.

-Passive and Active — “Passive” practice is following a textbook or studying flashcards. “Active” practice is listening to someone or trying to form a sentence of your own.

After 6 months of learning Python, I see these are all necessary approaches for learning (any) language as an adult. For those with humanities backgrounds, I hope this post will be useful in approaching your first computer language. NOTE: For all languages — I have learned that immersion is the fastest way to learn.

Python is like Spanish in that it seems easy at first, and then becomes very tricky to master. It’s high-level syntax and proximity to the English language can be decieving.

print(“hola mundo!”)
output: hola mundo!
some_list: [“1”, “2”, “3”]
for item in some_list:
    print item

Easy, right?

Guided, Passive Learning:

I began my journey with DataQuest and Codecademy, which are kind of like the Rosetta Stones of code. They show you some code, you copy it. Then the very guided excercises become gradually more challenging. This is a great way for adults to get a feel for what the language looks like, and the very basics of how it works. There is always solution code available, just like in Rosetta Stone will always repeat the word for you if you need. You go at your own pace.

If I had not started my class, I would never become a coder. Period. As when I used Rosetta Stone to learn French, DataQuest is just an introduction — I needed more to become fluent.

Guided, Active Learning:

In the first few weeks of the Data Science Immersive at General Assembly, we were given several types of lenctures (code-alongs, slide-style, whiteboard, interactive, etc.) and exercises called “labs”. Some of these were focused on how to covert mathematical and statistical formulas into Python, while others forced us to “think like a computer” — realizing that the machine will take everything literally and order is essential.

This is the part where the frustration of not having the answers begins to make your brain work — active learning. Each lab gave explicit instructions of what to do — i.e. the desired output is very clear — but this is when I became acquinted with *the docs*, otherwise known as documentation.

I would equate this experience to reading Spanish or French texts with the dictionary right next to you. It is slow, and certainly not as fun as reading a language you are fluent in, but is a necessary step before one moves into unguided practice.

Unguided, Passive Learning:

This is what many of us in the class call “the rabbit hole”. Unguided passive learning in Python

-Begins by trying to solve a problem by looking into the documentation on a function you’d like to use.

np.corrcoef(X_list_sqft, Y_list_price)
#trying to find the r value(correlation between a list of square feet and a list of prices of homes)
#Why is this giving me a whole matrix, instead of just the r value? Go to docs:


-Then you don’t understand what the documentation is saying, so you look at the source code (how the developer wrote the code to make said function).

def corrcoef(x, y=None, rowvar=1, bias=np._NoValue, ddof=np._NoValue):
“””Return Pearson product-moment correlation coefficients.
Please refer to the documentation for `cov` for more detail. The
relationship between the correlation coefficient matrix, `R`, and the
covariance matrix, `C`, is
.. math:: R_{ij} = \\frac{ C_{ij} } { \\sqrt{ C_{ii} * C_{jj} } }
The values of `R` are between -1 and 1, inclusive.

-Ah! Did you forget math? Go back and look at the formula… Then you get overwhelmed with how the source code works, and you look to Google to save you.

Google, how do I get a single r value for my coefficients?
Answer: Stack Overflow (a platform for sharing questions and answers about code) shows how to return just the r value instead of the matrix:
np.corrcoef(X_list_sqft, Y_list_price)[0,1] 
#since the type of the matrix is an “array”, you can slice it by the index

-(two hours later…) Now, where were we? This “rabbit hole” can be one of the most frustrating ways to learn. It is essential, however, to remember that this type of learning has value!! Coming to understanding on your own prepares you for unguided, active learning.

I would describe this process as sitting down to write an essay in Spanish, and then trying to figure out how to say something you haven’t practiced yet.

Unguided, Active Learning:

For me, this reminds me of when I had to negotiate rent with my landlady in Lyon, France. I had a goal (budget), and a need (a roof over my head). When I met with this woman, I had no smartphone or even a dictionary. I had to use only the French I knew to get what I needed. Then, I had to sign a lease (and hopefully, I understood the terms!)

I believe the work world will be like this most days, but our instructors attempt to simulate this in the projects and some of the labs we are beginning to do now (week 4 of 12). We have a goal, and we are given various degrees of prompting. For example, sometimes the data is provided, soon we will have to scrape it from the internet ourselves!

Then, we answer extremely general questions such as:

  • What does this data tell us about the music we like?
  • How should we make a decision on taxes based on liquor revenue from last year?

More Python/Spanish Comparisons:

Computers are literal. People are figurative/intuitive.

  • If you spell something wrong in Spanish, a human will try to understand it. Python will throw an error message.
  • “Types” in Python are kind of like parts of speech in spoken language, so syntax is important to fluent speech. But — humans will try to “fill in” the pronouns and other small words that typically trip you up, because communication is the goal, not precise direction. That is, communication goes two ways, code is pretty much just one-directional (except for error messages).
  • On the flip side, humans often misinterpret each other because we try to understand one another. Python will always throw an error if you make a syntax mistake.

Careful, though!! If you ask Python to do something and your syntax is correct, you called the correct functions on types that allow for that function, etc. — you can STILL get the wrong answer. But the computer will not look at you funny when you tell it something crazy.