Docsity

introduction au cours, Lectures de Informatique

Aperçu partiel du texte

Télécharge introduction au cours et plus Lectures au format PDF de Informatique sur Docsity uniquement!

An Introduction to Python

Juan F. Imbet Ph.D.

Paris Dauphine University

What is Python?

Python is a programming language that has been around for a while. However, only recently it has become popular for data science and machine learning applications.

Python is a:

. General purpose programming language . Interpreted language . Object-oriented language . High-level language . Dynamically typed language

Interpreted language

Python is an interpreted language, meaning that it is not directly translated into machine code. Instead, Python code is interpreted into Python bytecode , which is then interpreted (at runtime) into machine code.

Comparison to other programming languages

. C++ is a compiled language . Java is a compiled language . Python is an interpreted language . JavaScript is an interpreted language

Object-oriented language

Python is an object-oriented language. Everything in Python is an object. Objects have attributes and methods. Attributes are variables that belong to an object, and methods are functions that belong to an object.

Comparison to other programming paradigms

. Procedural programming: Focuses on logic and procedures. E.g. C and Fortran. . Functional programming: Focuses on functions and data. E.g. Haskell and Lisp.

Dynamic vs Static Typing

Python is a dynamically typed language. This means that variables do not have a fixed type. The type of a variable is determined at runtime, based on the value that is assigned to it.

Comparison to other programming languages . Dynamically typed languages like Python and JavaScript do not require variables to be declared before they are used. . Statically typed languages like C++ and Java require variables to be declared before they are used.

Python syntax

Python syntax is very clean, simple, and easy to understand. This is one of the reasons why Python is so popular for beginners.

Some unique features of Python syntax . Indentation is used to delimit blocks rather than curly braces . No semicolons are required to end statements . No variable declarations are required

SETTING UP YOUR ENVIRONMENT

Installing Python

There are two main versions of Python: Python 2 and Python 3. Python 2 is legacy, Python 3 is the current version. This course will use Python 3.

Installing Python Rather than installing Python directly, it is recommended to install a Python distribution. A Python distribution is a collection of Python packages that are pre-installed and pre- configured. This makes it easier to get started with Python.

. Windows - Anaconda . Mac - Anaconda . Linux - Anaconda . Online - Google Colab

Some useful extensions on VS Code

Jupyter Python

Preliminaries

Computer Architecture and Programming Languages

Computers think in binary (for now)

Computers are made of billions of tiny electronic components, which all work together to perform calculations. These components are called transistors. Transistors are made of semiconductors, which can be turned on and off by electricity. This is the basis of the binary system, which uses only two numbers (0 and 1) to represent all other numbers.

Binary numbers

A number expressed in a specific base can be expressed as , where is the number and is the base.

Example

How do we get the same number with powers of 2?

Who has the time to write binary code?

Binary code is very difficult to write and understand. For this reason, programming languages were invented. The first programming language that assembled code into binary was Assembly in 1949.

Example of Assembly code:

MOV AX, 5 MOV BX, 10 ADD AX, BX

But, who has the time (and skills) to write Assembly code?

(Very few people) Assembly code is still very difficult to write and understand. For this reason, programming languages were invented. The first programming language that compiled code into binary was FORTRAN in 1957.

Example of FORTRAN code:

PROGRAM ADD INTEGER A, B, C A = 5 B = 10 C = A + B END PROGRAM ADD

Look how it uses more human-readable words.