What You Will Learn about PYTHON


Python

Introduction to Python

is the starting point of your programming learning journey. In this module, you will discover the fundamental concepts of Python, a powerful and versatile programming language.


Course Modules:

Python Basics


Fundamentals

Python Basics is the starting point of your programming learning journey. In this module, you will discover the fundamental concepts of Python, a powerful and versatile programming language.


Module Contents

  • Basic Syntax
  • Data Types
  • Variables and Operators
  • Control Structures
  • Functions

Python Basics

Basic Input and Output

The classic "Hello, world!" program in Python is quite straightforward. To run it, click on the cell with your mouse and press Ctrl + Enter on your keyboard. You can also experiment by changing the text inside the quotes and running the program again.


PYTHON Console
print("Hello world!")
Hello world!

In the print function, numerical expressions are first evaluated and then automatically converted to strings. Subsequently the strings are concatenated with spaces:

PYTHON Console
print(1, "plus", 2, "equals", 1+2)
1 plus 2 equals 3

To read user input, use the input function with a string parameter that prompts the user. The entered string is stored in the variable name. Run the example below by pressing Control + Enter!

PYTHON Console
name=input("Enter your name: " )
print("Hello,", name )
Enter your name: AIT OUFKIR
Hello, AIT OUFKIR

Loops for Repetitive Tasks

In Python, there are two types of loops: while and for. We've already touched on the for loop briefly. Now, let's explore the while loop.

PYTHON Console
5 # Literal expression
3 / (5 + 0.2) # Arithmetic expression
a # Variable expression
cos(0) # Function call expression
obj.attr # Attribute reference expression


Statements

Statements are commands that perform an action. For instance, a function call that stands alone (not embedded in another expression) is a statement. Similarly, assigning a value to a variable is also a statement.

PYTHON Console
a = 5 # Variable assignment
a = a + 1 # Assignment and increment by 1
a += 1 # shorthand for incrementing

Note that in Python there are no operators ++ or -- unlike in some other languages. The operators like += -= *= /= //= %= &= |= ^= >>= <<= **= are augmented assignment operators in Python.



Loops for Repetitive Tasks

In Python, there are two types of loops: while and for. We've already touched on the for loop briefly. Now, let's explore the while loop.

PYTHON Console
i = 1 while i * i < 100: print("Square of", i, "is", i * i) i = i + 1

Square of 1 is 1
Square of 2 is 4
Square of 3 is 9
Square of 4 is 16
Square of 5 is 25
Square of 6 is 36
Square of 7 is 49
Square of 8 is 64
Square of 9 is 81
The squares below 100.



Another way of repeating statements is with the for statement.

PYTHON Console
t = 0 for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: t = t + i

The sum is 45



Python and Numpy

Introduction

The classic "Hello, world!" program in Python is quite straightforward. To run it, click on the cell with your mouse and press Ctrl + Enter on your keyboard. You can also experiment by changing the text inside the quotes and running the program again.


More Numpy

Introduction

The classic "Hello, world!" program in Python is quite straightforward. To run it, click on the cell with your mouse and press Ctrl + Enter on your keyboard. You can also experiment by changing the text inside the quotes and running the program again.


Pandas

Introduction

The classic "Hello, world!" program in Python is quite straightforward. To run it, click on the cell with your mouse and press Ctrl + Enter on your keyboard. You can also experiment by changing the text inside the quotes and running the program again.