Back
Close

Why Learn Python

[CG]Maxime
2,623 views

Why Learn Python

Python is a general purpose programming language. Created nearly 30 years ago, it is now one of the most popular language according to the TIOBE index. Its popularity is particularly important in the data science and machine learning fields. But it is also a language easy to learn, this explains why it has become the language the most taught in universities.

Python interpreters are available for the main operating systems (Linux, Mac OS, Windows, Android, iOS, BSD, etc.).

Python is easy to learn

Python has a simple syntax that makes it suitable for learning programming as a first language. The learning curve is smoother than other languages such as Java, which quickly requires learning about Object Oriented Programming or C/C++ that requires to understand pointers. Still, it's possible to learn about OOP or functional programming in Python when the time comes.

Python provides a well-furnished standard library and many external libraries are available. This allows to quickly develop concrete applications. Actually, developping a small project is a good way to stay motivated and keep learning!

What is python used for?

  • Web Development, using the frameworks Django, Flask, Pylons
  • Data Science and Visualization using Numpy, Pandas and Matplotlib
  • Machine learning with Tensorflow and Scikit-learn
  • Desktop applications with PyQt, Gtk, wxWidgets and many more
  • Mobile applications using Kivy or BeeWare
  • Education: Python is a great language to learn programming!

Python is a powerful language

  • Python is an Object Oriented Programming language. It even allows you to create classes with multiple inheritance.
  • Python offers the necessary features to allow you to program in functional programming: lambda, map, filter, reduce, partial...
  • Python checks the type of the variables during runtime, this makes the declaration of variable easier. But it's also possible to do static typing to catch potential bugs sooner.
  • Python has a very extensive standard library. It contains many types (lists, maps, sets, numerics, ...), it has IO functions to read/write files, mathematics functions (complex numbers, fractions, statistics functions, random...), compression (zlib, gzip, zip, ...), parsing (xml, csv, ...), cryptography, threads, sockets, http modules, graphical interface, and many more.
  • More that 150,000 libraries are available using the package management tool pip.

What Python Looks Like

Common Data Types

A list is an ordered sequence of values.

# Here's a list of integers:
l = [3, 5, 2, 7]
# Let's sort it:
l.sort()
# And print it:
print(l)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

A dictionary, commonly known as a hashmap or associative array, allows to associate a key to a value:

ages = {
'Alice': 32,
'Bob': 28
}
# This allows to access an element using a key:
print(ages['Bob'])
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Conditionals and Loops

Here's an example of condition:

age = 18
if age >= 18:
print("In most countries, you are major!")
else:
print("You're underage in most countries!")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And here's a for-loop that prints all the divisors of 3575:

n = 3575
for d in range(1, n + 1):
if n % d == 0:
print(f"{d} is a divisor of {n}")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Classes

Python is an Object Oriented Programming language. Here's a simple example of a class:

class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def print_age(self):
print(f"Age of {self.name} is {self.age}")
arthur = Person("Arthur", 31)
arthur.print_age()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Guess Game

Here's the source code of a small game where the player has to guess a random number:

# {...}
from random import randint
number_to_guess = randint(0, 100)
n = int(input('Guess my number! '))
while n != number_to_guess:
if n < number_to_guess:
print('Too small!')
else:
print('Too big!')
n = int(input('Try again: '))
print('Congratulation! You found it!')
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Learn more!

Check out my other playgrounds:

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants