General Python FAQ

What is Python?

Python is general-purpose programming language with which you can do data engineering, produce publication-quality graphs, run statistical analysis, apply ML & AI to mine massive data and even build websites.

Why is it called Python?

Python was named after "Monty Python's Flying Circus" which is the author (Guido van Rossum)'s favorite TV show. For some reason, all the book publishers choose to use the huge snake on the cover.

Python Vs. R?

R originated from the math/statistics community, which shapes R as a perfect statistical language/tool in the first place. Python however was implemented as a general-purpose high-level programming language. When working with R, your focus is "model, regression, left/right side of the equation", however, when you learn Python, you start with language syntax, data structures and then move onto the topics of packages.

Which one is running faster: Python VS. R?

A: In terms of the performance of looping, Python runs faster than R. But, both languages support vectorized operations that allows operations run in a vector/matrix fashion. Note that in most cases, we are not seeking a "speed booster", especially for academics.

Run a loop of 100,000 iterations in R

ptm <- proc.time() 
for(i in 1:100000) {
   print(i)
}
print("finished!")
print(proc.time() - ptm)
#  user  system elapsed 
# 43.904   0.086  45.046

Run a loop of 100,000 iterations in Python

import time
timer_start = time.time() 
for i in range(1, 100001):
    print(i) 
print("Finished!") 
timer_end = time.time() - timer_start 
print(timer_end)
# 13.08002

Stackflow Survey 2020

Most commonly used language

Most loved

Most dreaded

Most wanted

Python 2.x Vs. Python 3.x

The short answer is Python 2.x is a legacy, and Python 3.x is the current and future Python. The update-to-date release is Python 3.9, which was released on Oct. 5th, 2020. Note that as of January 1, 2020, the 2. x branch of the Python programming language is no longer supported by its creators, the Python Software Foundation.

Some Syntax differences between 2.x and 3.x

  1. Division operation

    • In Python 2.x: 7/5 = 1 Why? The reason is 7 and 5 are both integers, so the result is an integer. It is not surprising if you happen to some programming expereinces
    • In Python 3.x: 7/5 = 1.4 Why? Python 3.x caters more for the public or data folks who do not have much programming background
  2. Print function:

    • In Python 2.x: print 'I love Python!'
    • In Python 3.x: print('I love Python!') It is noted that a pair of parentheses is required!
In [ ]: