PYTHON
Tutor: Nguyễn Lê Chí Bảo
01 03
Introduction to Python Numpy
MODULE
02 04
Function Pandas
MODULE 1.
INTRODUCTION TO
PYTHON
Module 1:INTRODUCTION TO PYTHON
Introduction to Python
Basic syntax
Decision Making
Loops
Introduction to Python
Module 1: INTRODUCTION TO PYTHON
What is Python used for?
• Web Development.
• Data Analysis
• Internet of things
• Web Scraping
• Computer Vision
• Machine learning
Module 1: INTRODUCTION TO PYTHON
Why Python?
• Solve complex problems in less time with fewer lines of code.
• High-level
• Cross-platform
• Huge Community
• Large Ecosystem
Module 1: INTRODUCTION TO PYTHON
Programing Modes?
• Interactive Mode
• Script Mode
Basic syntax
Module 1: INTRODUCTION TO PYTHON
Line and Indentation
• No braces for blocks of code
• Line indentation indicate blocks of code
• Same number of spaces for each line in a block of code
• The number of spaces in the indentation is flexible
Module 1: INTRODUCTION TO PYTHON
Identifiers
• Starts with a letter A to Z or a to z or an underscore (_)
• Could have any letters, underscores and digits (0 to 9)
• Case sensitive programming language
Module 1: INTRODUCTION TO PYTHON
Reserved Words
and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield
Module 1: INTRODUCTION TO PYTHON
Comments
A hash sign (#) starts a comment
Module 1: INTRODUCTION TO PYTHON
Variables
• Variables are reserved memory locations to store values.
• Python variables do not need explicit declaration to reserve memory space
• The declaration is automatically when you assign a value to a variable by using the equal sign (=)
• Could assign a single value to several variables simultaneously
• Could assign multiple objects to multiple variables.
Module 1: INTRODUCTION TO PYTHON
Input/Output operators
• Input and output (I/O) operators are used to take input and display output
Module 1: INTRODUCTION TO PYTHON
Data Types
• Numbers: 5, 4.2, …
• String: “Hello world”, …
• List: [1,2,3,4], [“abc”,”xyz”,123]
• Tuple: (1,2,3,4)
• Dictionary: {‘a’: 1, ‘b’: 2}
• Set
Module 1: INTRODUCTION TO PYTHON
Data Type Convention
• int(x [,base]) : Converts x to an integer. Base specifies the base if x is a string.
• long(x [,base] ) : Converts x to a long integer. base specifies the base if x is a string.
• float(x) : Converts x to a floating-point number.
• complex(real [,imag]) : Creates a complex number
• str(x) : Converts object x to a string representation
• tuple(s) : Converts s to a tuple.
• list(s) : Converts s to a list.
• set(s) : Converts s to a set.
• dict(d) : Creates a dictionary. d must be a sequence of (key,value) tuples.
Module 1: INTRODUCTION TO PYTHON
OPERATORS - Arithmetic Operators
Module 1: INTRODUCTION TO PYTHON
OPERATORS – Comparison Operators
Module 1: INTRODUCTION TO PYTHON
OPERATORS – Assignment Operators
Module 1: INTRODUCTION TO PYTHON
OPERATORS – Logical Operators
Module 1: INTRODUCTION TO PYTHON
OPERATORS – Membership Operators
Module 1: INTRODUCTION TO PYTHON
Data Type – Numbers
• int (signed intergers)
• float (floating point real values)
• complex (complex numbers with the form a+bi)
Module 1: INTRODUCTION TO PYTHON
Data Type – Numbers
Number Type Conversion:
• int(x) to convert x to a plain integer
• float(x) to convert x to a floating-point number
• complex(x,y) to convert x and y to a complex number with real part x and imaginary part y.
x and y are numeric expressions
Module 1: INTRODUCTION TO PYTHON
Data Type – Numbers
Mathematical Functions:
• abs(x) : The absolute value of x
• exp(x) : The exponential of x
• log(x) : The natural logarithm of x, for x > 0
• pow(x,y): The value of x**y
• sqrt(x): The square root of x, for x > 0
Module 1: INTRODUCTION TO PYTHON
Data Type - String
• Single ('), double (") and triple (''' or """) quotes to denote string literals
• The triple quotes for multiple line strings
• Ex:
language = ‘python’
subject = “D4E”
paragraph = ””” The training duration is more focus on python ”””
Module 1: INTRODUCTION TO PYTHON
Data Type - String
Escape Characters
Module 1: INTRODUCTION TO PYTHON
Data Type - String
String Special Operators
Module 1: INTRODUCTION TO PYTHON
Data Type - String
Built-in String Methods
Module 1: INTRODUCTION TO PYTHON
Data Type - List
• Lists are used to store multiple items in a single variable.
• Lists are one of 4 built-in data types in Python used to store collections of data, the other 3
are Tuple, Set, and Dictionary, all with different qualities and usage.
• Lists are created using square brackets
• List items are ordered, changeable, and allow duplicate values.
• List items are indexed, the first item has index 0, the second item has index 1 etc.
Element 0 Element 1 Element 2
Module 1: INTRODUCTION TO PYTHON
Data Type - List
Module 1: INTRODUCTION TO PYTHON
Data Type - List
Module 1: INTRODUCTION TO PYTHON
Data Type - List
Decision Making
Module 1: INTRODUCTION TO PYTHON
IF Statement
Module 1: INTRODUCTION TO PYTHON
IF Statement
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Module 1: INTRODUCTION TO PYTHON
AND – OR – NOT
A B A AND B A OR B NOT A
TRUE TRUE TRUE TRUE FALSE
TRUE FALSE FALSE TRUE FALSE
FALSE TRUE FALSE TRUE TRUE
FALSE FALSE FALSE FALSE TRUE
Loops
Module 1: INTRODUCTION TO PYTHON
For Loop
for <var> in <iterable>:
<statement(s)>
Module 1: INTRODUCTION TO PYTHON
While Loop
while <condition>:
<statement(s)>
Module 1: INTRODUCTION TO PYTHON
Break and Continue
break: To stop the loop immediately.
continue: Skip current item of a loop.
THANKS
CREDITS: This presentation template was created by
Slidesgo, including icons by Flaticon, and Name: Nguyễn Lê Chí Bảo
infographics & images by Freepik and illustrations Email:
[email protected]by Storyset Phone: 091 544 2420
Linkedin: nguyenlechibao