Main characteristics#

Has to be there#

Few characteristics of the Python language and ecosystem…

  • Definition keywords and “built-in identifiers” (https://docs.python.org/3/library/builtins.html)

  • Notions of assignment, names, references

  • First name space / object space diagram

  • Keyword del

  • Built-in functions type()

  • A reference interpreter and few alternative interpreters

    • CPython

    • PyPy

    • GraalPy

    • MicroPython

Take away: dynamic languages strong thanks to tooling and testing.

Open-source language, interpreters and ecosystem#

Interpreted (but there are tools to compile Python code)#

Automatic memory management#

Dynamically strongly typed: types, objects and variables#

The function type returns the type of an object:

type("hello")
str
type(2)
int
type(2.0)
float
type(2 + 2)
int
type(2 + 2.0)
float
type(True)
bool

Variables are just tags pointing towards objects. New variables can be used when needed. They are not associated with a type but only with an object (which has a type)…

myvar = 1
print(myvar, type(myvar))
1 <class 'int'>
myvar = "hello"
print(myvar, type(myvar))
hello <class 'str'>

Spaces for objects and variables (names)#

Objects and variables (names) are two very different concepts:

  • Objects live in one “object space”. They have an address in the memory.

  • Names live in namespaces.

It is often interesting to represent the execution of a Python program in an “object space - namespaces” diagram.

The Zen of Python says “Namespaces are one honking great idea – let’s do more of those!”. A namespace is created for every module (file) and for every function execution,

Gradual learning curve#

A philosophy: the Zen of Python#

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Very clean and readable#

Indentation defines the blocks#

Style coding is important: PEP 8#

PEP: Python Extension Proposal

From the Wikipedia article:

Python’s development is conducted largely through the Python Enhancement Proposal (PEP) process, the primary mechanism for proposing major new features, collecting community input on issues, and documenting Python design decisions.

  • Code layout

  • Imports

  • White spaces in expressions and statements

  • Comments

  • Documentation strings

  • Naming conventions

  • Programming recommendations

PEP8: examples of bad and good style practices#

# bad (spaces between operator)
number=0
# ok
number = 0
# bad (indentation with 2 spaces, has to be 4)
if number == 0:
  number = 1

# ok
if number == 0:
    number = 1
# bad (space after ,)
mylist = [1,2,3]

# ok
mylist = [1, 2, 3]

Only few keywords and built-in functions#

  • Keywords,

help("keywords")
Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not                 

Errors should never pass silently#

Multi-paradigm (sequential, object-oriented, functional)#

“Batteries Included”: the standard library#

Huge success, strong community and huge ecosystem#

In 2024:

GitHub also provides insights into their users’ language preferences:

  • The top three programming languages are JavaScript, Python, and Java.

  • PHP has decreased in popularity, dropping from sixth to seventh place in 2022.

  • The Hashicorp Configuration Language (HCL) is the fastest-growing language on GitHub, with a usage increase of 56.1 percent.

  • Rust experienced a growth rate of more than 50 percent, which GitHub attributes to its security and reliability.

  • Python continues to grow in popularity, with a 22.5 percent increase per year.

JOSS reviews are primarily about the software, and so it would be remiss of us not to talk about that. Python is still the #1 language for JOSS submissions, used in part for well over half of published papers (~1200 out of 2000). R is #2 at 445 submissions, and C++ #3 (although of course C++ and C may be used together with another language).