0% found this document useful (0 votes)
6 views24 pages

01_Python_fundamentals_and_Jupyter_Notebooks

This document outlines a summer school session focused on Python fundamentals and Jupyter Notebooks, detailing learning outcomes, programming concepts, and practical applications of Python. It covers topics such as variables, conditions, loops, functions, and file handling, along with the use of libraries and modules. Additionally, it provides resources for software installation and documentation for further learning.

Uploaded by

NORA SALMERON
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views24 pages

01_Python_fundamentals_and_Jupyter_Notebooks

This document outlines a summer school session focused on Python fundamentals and Jupyter Notebooks, detailing learning outcomes, programming concepts, and practical applications of Python. It covers topics such as variables, conditions, loops, functions, and file handling, along with the use of libraries and modules. Additionally, it provides resources for software installation and documentation for further learning.

Uploaded by

NORA SALMERON
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Summer School: Artificial intelligence in industrial applications

Programming Session 1: Python fundamentals and Jupyter Notebooks


Jiyoung Moon
Aachen, 26.06.2025
Learning outcomes

Fundamental knowledge of Python and Jupyter

Variables

How to use
Loops How to
it
use it

Libraries Python Conditions Benefits Jupyter Markdown

Modules, Scripts
Operators
Packages

Scripts
Programming language: Python

The most popular programming languages worldwide


according to the PYPL Index in July 2023

• Language with multiple application areas:


− Web Development
− GUI Development
− Scientific Operations
− Home Automation
− Data Science
• Interpreter Language
• Development of Python started in 1989

Source: Statista
Why python and what can I do with python ?

• Syntax is clear, easy to read and learn • Intuitive object-oriented programming


(almost pseudo code)
• Full modularity with hierarchical packages
• Versatility
• Comprehensive standard library for many tasks
▪ Website development
▪ Data analysis • Big community
▪ Server maintenance
• Simply extendable via C/C++, wrapping of C/C++
▪ Numerical analysis libraries
• Widely adopted • Focus: Programming speed
Three different ways to use Python

Method 1: Interactive Python interface Method 2: Create Python script files (*.py)
• Where to write code:
− Use simple Text Editors
− Use integrated development environments (IDE)
(for example, Visual Studio Code)
Three different ways to use Python

Method 3: Python Notebooks


• Where to write code:
− Directly in the web browser using Jupyter
Notebook
Jupyter

• Jupyter Notebook is a web-based interactive computational environment for


creating notebook documents

• A notebook integrates code and its output into a single document that combines
visualizations, narrative text, mathematical equations and other rich media

• Jupyter Notebook supports multiple languages

• Two types of input cells: Python Code and Markup Code


Programming experience

Discussion

Discuss in small groups:


What are your programming experiences? Why do we need programming skills? What do you want to with your
programming skills?

Image Source: Pixabay


Software requirements

Python 3.10:
• https://www.python.org/downloads/

Jupyter Notebook:
• https://jupyter.org/install

Visual Studio Code:


• Code Editor
• https://code.visualstudio.com/docs
Python documentation

• To learn how to read the documentation is the key to


learn a new programming language

• Cheat sheets often help

Documentation:
https://docs.python.org/3/tutorial/index.html
https://www.w3schools.com/python/default.asp
Markup language

Element Markdown Syntax


• Text can be added to Jupyter Notebooks using
Heading # H1
Markdown cells ## H2
### H3
• change the cell type to Markdown by using the Cell
Bold **bold text**
menu, the toolbar, or the key shortcut
Italic *Italicized text*
• Markdown is a popular markup language that is a Blockquote > Blockquote
superset of HTML Ordered List 1. First item
2. Second item
3. Third item
Unordered List - First item
- Second item
- Third item
Code ‘code’
Horizontal Rule ---
Documentation:
https://www.markdownguide.org/cheat-sheet/ Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Python - Variables

Python • Variables are used to store data in Python.


# Integers
a = 7 • No predefining of data types is necessary when
storing variables
# Sum
sum_1 = 1 + 3 # Result is 4
− Variables can also store values obtained from
# Division mathematical statements.
div_1 = 7 / 3.0 # Result is 2.3333
− Variable definition example: x = 6
# Integer Division
div_2 = 7//3
is
# Result is 2

# Strings
s1 = “Hello World“ Use lowercase letters with underscores for variables,
s2 = “Hello World“
functions, methods, packages and modules.
Use capital letters with underscores for constants.

Documentation:
https://docs.python.org/3/tutorial/introduction.html
Python - Operation overview

Operator Description Application


= Assign Values x = 2, y = 3.14, z = ‘hi‘

<, >, Comparison for Smaller, Bigger 1 + 1 == 2, 1 < 2, 2 > 1


==, <=, >= and Equality
!= Comparison for Inequality 3 != 4, ‘a’ != ‘b’

+, -, *, / Simple Arithmetic Operations 1+2, a*b, b+1

% Modulo 5 % 2 == 1

+=, -=, *=, Direct application of operation a += 2 ( a = a + 2 )


/=
and, or, not Logical operators True and True == True

print() Printing to Console print(“Hello World”)

+ Concatenation for Lists and Strings ‘Hel’ + ‘lo’ == ‘Hello’

Documentation:
https://docs.python.org/3/tutorial/introduction.html
Python - Conditions

Python • if-statements check if logical expressions


# If-Else Condition are true
if condition1: − Example Condition: 1+1==2
print("Condition 1 is True")
else:
print("Condition 1 is False")
• The else-statement defines the case that a
statement is not true
# Condition with logical operators
if condition1 and condition2: • Multiple conditions can be concatenated by
print("Condition 1 and 2 are True") using logical operators
if condition1 or condition2:
print("Condition 1 or 2 is True")
• Multiple cases can be differentiated by
# Condition with elif elif-statements.
if condition1:
print("Condition1 is True")
elif condition2: Indentation is very important
print("Condition2 is True")
else:
print("Conditions 1 and 2 are False") Documentation:
https://docs.python.org/3/tutorial/controlflow.html
Mini Task: What will be printed in the console?

Python Python
i=1 # Exercise 3

# Exercise 1 x = 20
if i<1: y = 15
print("1")
if i==1: if x > y:
print("2") print("x is greater than y")
else: if x > 25:
print("3") 1)3 print("x is greater than 25")
2)2
3)x is greater than y if x > 30:
# Exercise 2 x is less than or equal to 25 print("x is greater than 30")
if i<1: else:
print("1") print("x is less than or equal to 30")
else: else:
if i==1: print("x is less than or equal to 25")
print("2") else:
print("3") print("x is less than or equal to y")
Mini Task: Solution

Python Python
i=1 # Exercise 3

# Exercise 1 x = 20
if i<1: y = 15
print("1")
if i==1: if x > y:
print("2") print("x is greater than y")
else: if x > 25:
print("3") print("x is greater than 25")
if x > 30:
# Exercise 2 print("x is greater than 30")
if i<1: else:
print("1") print("x is less than or equal to 30")
else: else:
if i==1: print("x is less than or equal to 25")
print("2") else:
print("3") print("x is less than or equal to y")
Mini Task: Solution

Python Python
i=1 # Exercise 3

# Exercise 1 x = 20
if i<1: y = 15
print("1")
if i==1: if x > y:
print("2") print("x is greater than y")
else: if x > 25:
print("3") print("x is greater than 25")
if x > 30:
# Exercise 2 print("x is greater than 30")
if i<1: else:
print("1") print("x is less than or equal to 30")
else: else:
if i==1: print("x is less than or equal to 25")
print("2") else:
print("3") print("x is less than or equal to y")
Python - Loops

Python • For-Loops:
# Basic approach − Iterate over a list of values
sum = 0
sum += 1
− Common lists can be created ad-hoc
print(sum)
sum += 2 • While-Loops:
print(sum)
… − Iterate over a list of values
sum += 100 − Useful when the number of iterations is uncertain
print(sum)

# For-Loop • Example: Calculate and print the sum of all values


sum = 0
for index in range(1, 101):
between 1 and 100
sum += index
print(sum)

# While-Loop
sum = 0 Use for-loops for efficient and compact iteration.
index = 1
while index <= 100: Use while-loops cautiously to avoid infinite loops.
sum += index
print(sum) Documentation:
index += 1
https://docs.python.org/3/tutorial/controlflow.html
Python - Functions

Python • Allows you to group and organize code for


# Definition of a function reusability
def function_name(
parameter_1, • Consist of a block of code with a name and optional
parameter_with_default_value = value):
#function body
parameters
return function_output_1, function_output_2
• Define a function using the def keyword, followed
by the function name and optional parameters
# Example Function: Addition of two values
def addition(value1, value2):
result = value1 + value2
• Use the function by calling its name and providing
return result the required arguments

# Use the function


new_value = addition(0, 30)
Use functions for modular and reusable code,
improving maintenance and readability.

Documentation:
https://docs.python.org/3/tutorial/controlflow.html
Scripts, modules, packages, and libraries

• Important Python Terms:

− Script: Python file that’s intended to be run directly and do something

− Module: Python file that’s intended to be imported into scripts or other modules

- Used to define functions, and variables intended to be used in other files

− Package: Collection of modules to provide certain functionality

− Library: Consists of a lot of different modules

- For example, Matplotlib is a plotting library

• These are not strict definitions but give you more understanding of how the Python community works
Installing and importing libraries

Console • Libraries that are not part of pure Python can be


(python env) > pip install library_name installed and imported to add new functionalities
(python env) > pip install pandas
• Especially for Data Science and AI there are a lot of
different packages available
(python env) > conda install library_name
(python env) > conda install numpy • Most important packages are:
− Numpy − Keras
− Pandas − SciKit-Learn
Python − Matplotlib − PyTorch
import package_name as internal_identifier
from package_name import certain_class
− TensorFlow − Seaborn
− SciPy
import numpy as np
import pandas as pd
Internal Identifier are most of the time predefined.
For most packages there are cheat sheets available
function_return = which help to use the package
internal_identifier.function(parameters)
Documentation:
https://docs.python.org/3/tutorial/modules.html
Python - Reading and writing files

Python • Reading Files:


# Open a file in read mode − Use the open() function with “r” mode to read
file = open("example.txt", "r") files in python
# Read the entire content of the file
content = file.read()
− Function takes the file name and access mode as
# Close the file parameters
file.close()
# Print the content read from the file • Writing Files
print(content) − Use the open() function with "w" mode to write
files
# Open a file in write mode − The write() method writes data to the file
file = open("example.txt", "w") through the file object
# Write data to the file
file.write("Hello, World!")
# Close the file
Remember to close the file after reading or writing
file.close() using the close() method to release system
resources
Documentation:
https://docs.python.org/3/tutorial/inputoutput.html
Exercise
Exercise discussion

You might also like