Understand Python

Python is one of the original triplet of the so called Scripting languages Perl, Python and Ruby. There is no specific definition of what Scripting language is, but loosely it is a language that is Interpreted, good at fast prototyping, dynamically typed.

Perl showed how useful a scripting language can be, but many people didn’t like the syntax. At the same time Java was on the horizon promising Object oriented paradise.

So two languages tried to create better Perl one called Python the other Ruby. Both promised Object oriented scripting language. 

Learn

Overall Python is easy to use and learn, that is one of the reasons of its popularity.

It is interesting that one of the most contentious bug/feature of Python is the use of indentation which is used to figure where a code block starts and where it ends. The industry standard is to use brackets. 

As you use the language you will get used to it. It is most annoying for beginners because those are the persons that would most often Copy&Paste code which have to be adjusted afterwards. It will also be confusing for people coming from another language.

Python is the closest thing that humans will write code if they didn’t knew any programming i.e. it is closest thing to be interpreted as pseudo code.

Is it worth it ?

Python is one of the most popular language in the world, so it should be easy to find a job.

It is good as a starting language. Because it is easy, you will know pretty fast are you up to the task. If it is too hard, may be programming is not for you. Of course I’m talking about the Syntax of the language and the Process of writing a program, the Concepts will always feel weird in the beginning.

Python is also good to quickly test an idea, scrap it, try again … and again

One famous problem which is characteristic of all scripting languages is the so called GIL (Global Interpreter Lock) which prohibit them to be truly multi-threading languages, but you as a newcomer wont be disadvantaged, quite the opposite it will benefit you because it makes Python easier to learn. /No need to learn multi-threading/

With the growth of the popularity the ecosystem of available libraries is enormous. You can find almost anything. What this means is you don’t have to build everything from scratch and can concentrate on the problem you want to solve.
Here are some options :

  • Numerical processing : numpy, pandas, scipy, dask, vaex
  • Machine learning : scikit, keras, pythorch, tensor flow
  • “Solving” the GIL lock : pypy, Cython, numba, Ray
  • Ploting, Graphing : matplotlib, bokeh, plotly
  • Web development : web.py, Flask, Django
  • Logic&Probabalistic programming : problog, datalog
  • … and many more

And let’s not forget again because Python is popular there are many well paid jobs to pick from [Jobs recommendation].

Pros and Cons

This section will allow me to introduce you to some quirks in the language and at the same time will introduce you to some new concepts.

Love

Duct typing

“If it walks like a duck and it quacks like a duck, then it must be a duck”

Remember the Variable as a Box analogy, what if we can put a tag on the boxes and agree we can only put objects that match the tag inside. We can’t do operations with boxes that have different tags.
In statically typed languages we set the tag at beginning and we can’t change it. In Python it is different story the Box tag automatically changes depending what we put inside. This is what it means to be dynamically typed.

Now let’s stretch our abstraction even further. What if we now allow to put labels on the boxes that describe what we can do with the object in the box. The tag is still there we just add labels. And again when we put object inside the box, both the tag and the labels change, still dynamic typing.

Now we introduce a rule that as long as two Variables have the same Labels, we can do the operation even if they have different tags. That is duct typing, as long as Variables behave the same they can be treated the same, no matter what their type is.

List comprehension

Normally you would use loops to manipulate sets, Lists and Dictionaries.

In many cases you can use a shorter and faster variant called List comprehension. It has the same semantics as a loop, but is more compact to write. It comes from Functional languages which borrowed it from Math, you probably have seen declarations like this {x : x is 1 .. 10 }.

iterators and generators

iterators in Python are standard API interface that is recognized by the control flow operators such as loops and thus allow any class to be iterated if it implements this protocol. This way you can iterate easy over complex data structures and data streams.

generators return iterators.

Decorators

Decorators are Functions that return Functions. They allow to wrap Functions in such a way so you can control, modify and extend their behavior.

Hate

Indentation

Hate is a strong word, but using indentation can be annoying at times. Especially when copying code around.

Miss

Multi method dispatch

Python does not support multi method dispatch, there are modules for it but it is not the same.

  • OK! So what is it ?
  • Glad you asked.
  • Did you wonder what happens if you have two methods with the same name ?
  • Collision ?
  • Correct. What about if they have different arguments ?
  • Dunno, you tell me !
  • In Python it does not matter it is still an error.
  • And !?
  • The case where the Language can distinguish between methods with different signatures is called Multi method dispatch.
  • Got it, what good is it ?
  • It makes your API more consistent. Imagine having no word “say” and instead of using “say a number, say a word, …”, every time have to invent totally new word like “say-number, say-word, ..” you have to remember all those words, instead of just using composition from the word “say” and whatever come next.
  • That would suck …

Where to start ?

First learn the programming [Concepts].

Then a good place to start is here [Learn Python]

What to do if I’m stuck ?

  • print() is your friend
  • Install IPython REPL and use it extensively
  • watch a youtube video for 10 min and then get back
  • search and then ask on stackoverflow.com

Still have questions

Check the Python FAQ page and Python Interview questions