About me
• Education
• NCU (MIS)、NCCU (CS)
• Work Experience
• Telecom big data Innovation
• AI projects
• Retail marketing technology
• User Group
• TW Spark User Group
• TW Hadoop User Group
• Taiwan Data Engineer Association Director
• Research
• Big Data/ ML/ AIOT/ AI Columnist
2
What can Python do?
•Console application
•Desktop application
•Web application
•Mobile application
•Machine Learning
•Data Science
•IOT application
•And many more …
5
Python version
• Python 0.9.0 - February 20, 1991
• Python 0.9.1 - 1991
• Python 0.9.2 - 1991
• Python 1.0 - January 1994
• Python 1.2 - April 10, 1995
• Python 1.3 - October 12, 1995
• Python 1.4 - October 25, 1996
• Python 1.5 - December 31, 1997
• Python 1.6 - September 5, 2000
• Python 2.0 - October 16, 2000
• Python 2.1 - April 15, 2001
• Python 2.2 - December 21, 2001
• Python 2.3 - July 29, 2003
• Python 2.4 - November 30, 2004
• Python 2.5 - September 19, 2006
• Python 2.6 - October 1, 2008
• Python 2.7 - July 3, 2010
6
Python 3.0 - December 3, 2008
Python 3.1 - June 27, 2009
Python 3.2 - February 20, 2011
Python 3.3 - September 29, 2012
Python 3.4 - March 16, 2014
Python 3.5 - September 13, 2015
Python 3.6 - December 23, 2016
Python 3.7 - June 27, 2018
Python 3.8 - October 19, 2019
Python 3.9 - October 05, 2020
Python 3.10 - October 04, 2021
Python features
• Easy to learn, fast to develop
• The grammar is easy to learn and understand, suitable for beginners,
and can accelerate the learning of other languages.
• Several lines of code can be used to complete complex tasks.
• Cross-platform (cross-operating system)
• Powerful standard library (internal modeling group)
• Python built-in standard function library, providing a wide range of
internal modeling groups, such as: text
7
Life is short, you need Python.
• Python classic third-party package
• Web framework: Django, Flask, Pyramid, web2py
• GUI development: PyQt, Tkinter, wxPython App development: kivy
• Crawler: Scrapy, selenium, beautifulsoup
• Data science: numpy, scipy, matplotlib, pandas Machine learning:
keras, tensorflow
• Python official kit website: Pypi
8
Python Programming Basics for Beginners
• Install Anaconda for Windows (Individual Edition)
• https://www.anaconda.com/products/individual
11
Python Programming Basics for Beginners
• print() function
• The print() function in Python is used to print a specified message on the
screen. The print command in Python prints strings or objects which are
converted to a string while printing on a screen.
• print blank lines
• Sometimes you need to print one blank line in your Python program.
Following is an example to perform this task using Python print format.
12
python_exercise_01.ipynb
Python Programming Basics for Beginners
• How to Declare and use a Variable
• Re-declare a Variable
• Python String Concatenation and Variable
• Python Variable Types: Local & Global
• Delete a variable
13
Python Data Structure
• Python TUPLE
• Tuple Matching in Python is a method of grouping the tuples by matching the
second element in the tuples. It is achieved by using a dictionary by checking
the second element in each tuple in python programming. However, we can
make new tuples by taking portions of existing tuples.
• Tuple packing and unpacking.
• Comparing tuples.
• Using tuples as keys in dictionaries.
• Deleting Tuples.
• Slicing of Tuple.
14
Python Data Structure
• Advantages of tuple over list
• Iterating through tuple is faster than with list, since tuples are immutable.
• Tuples that consist of immutable elements can be used as key for dictionary,
which is not possible with list
• If you have data that is immutable, implementing it as tuple will guarantee
that it remains write-protected
15
Python Data Structure
• Try
• To perform different task, tuple allows you to use many built-in functions like
all(), any(), enumerate(), max(), min(), sorted(), len()
16
Python Dictionary
• A Dictionary in Python is the unordered and changeable collection of
data values that holds key-value pairs.
• Each key-value pair in the dictionary maps the key to its associated
value making it more optimized.
• A Dictionary in python is declared by enclosing a comma-separated
list of key-value pairs using curly braces{}.
• Updating Dictionary
• Delete Keys from the dictionary
• Dictionary items() Method
• Sorting the Dictionary
• Merging Dictionaries
17
Python Dictionary
• The ** is called Kwargs in Python, and it will work with Python version
3.5+. Using **
• We can merge two dictionaries, and it will return the merged
dictionary.
18
Python Dictionary
• Dictionary is one of the important data types available in Python. The
data in a dictionary is stored as a key/value pair. It is separated by a
colon(:), and the key/value pair is separated by comma(,).
• Python Dictionary Append
• Accessing elements of a dictionary
• Deleting Element(s) from dictionary using pop() method
• Appending element(s) to a dictionary
• Updating existing element(s) in a dictionary
• Insert a dictionary into another dictionary
19
Python Operators
• Logical Operators in Python are used to perform logical operations on
the values of variables. The value is either true or false. We can figure
out the conditions by the result of the truth values. There are mainly
three types of logical operators in python : logical AND, logical OR and
logical NOT. Operators are represented by keywords or special
characters.
• Arithmetic Operators
• Comparison Operators
• Python Assignment Operators
• Logical Operators or Bitwise Operators
• Membership Operators
• Identity Operators
20
Python Arrays
• A Python Array is a collection of common type of data structures
having elements with same data type. It is used to store collections of
data. In Python programming, an arrays are handled by the “array”
module. If you create arrays using the array module, elements of the
array must be of the same numeric type.
• insert elements
• modify elements
• pop an element from Array
• delete elements
• Search and get the index of a value in an Array
• Reverse an Array
• Traverse an Array
21
Python Arrays
• What is the difference of array and list
• Data type is different
• array: all elements must be all the same type
• list (linked-list): all elements can be multiple data types
22
Python Conditional Loops
• Conditional Statement in Python perform different computations or
actions depending on whether a specific Boolean constraint evaluates
to true or false. Conditional statements are handled by IF statements
in Python.
• Python if Statement
• else condition
• elif condition
• conditional statement with minimal code
• Nested if Statement
• Switch Case Statement
23
Python For & While Loops
• What is Loop?
• Loops can execute a block of code number of times until a certain
condition is met. Their usage is fairly common in programming. Unlike
other programming language that have For Loop, while loop, dowhile, etc.
• What is For Loop?
• For loop is used to iterate over elements of a sequence. It is often used
when you have a piece of code which you want to repeat “n” number of
time.
• What is While Loop?
• While Loop is used to repeat a block of code. Instead of running the code
block once, It executes the code block multiple times until a certain
condition is met.
24
Python break, continue, pass statements
• The break statement takes care of terminating the loop in which it is
used. If the break statement is used inside nested loops, the current
loop is terminated, and the flow will continue with the code followed
that comes after the loop.
• break statement
• break statement inside while-loop
• break Statement inside nested loops
• The continue statement skips the code that comes after it, and the
control is passed back to the start for the next iteration.
• Continue inside for-loop
25
Python break, continue, pass statements
• Python pass statement is used as a placeholder inside loops,
functions, class, if-statement that is meant to be implemented later.
• pass
• pass statement inside the loop
26
Python OOPs
• OOPs in Python is a programming approach that focuses on using
objects and classes as same as other general programming languages.
The objects can be any real-world entities. Python allows developers
to develop applications using the OOPs approach with the major
focus on code reusability. It is very easy to create classes and objects
in Python.
• Inheritance works
• Constructors
27
String
• In Python everything is object and string are an object too. Python string
can be created simply by enclosing characters in the double quote.
• String replace()
• Changing upper and lower case strings
• join function
• Reversing String
• Split Strings
• string format()
• class with format()
• dictionary with format()
• Padding Variable Substitutions
• find() using start and end arguments
28
function
• Python main function is a starting point of any program. When the
program is run, the python interpreter runs the code sequentially.
Main function is executed only when it is run as a Python program. It
will not run the main function if it imported as a module.
• __name__ variable and Python Module
• defile function
29
lambda function
• A Lambda Function in Python programming is an anonymous function
or a function having no name. It is a small and restricted function
having no more than one line. Just like a normal function, a Lambda
function can have multiple arguments with one expression.
• lambdas in filter()
• lambdas in map()
• lambdas in reduce()
• abs(), round(), range(), map()
30
Generators
• Generators are functions that return an iterable generator object.
• The values from the generator object are fetched one at a time
instead of the full list together and hence to get the actual values you
can use a for-loop, using next() or list() method.
• read the values from the generator
31
Queue
• A queue is a container that holds data.
• The data that is entered first will be removed first, and hence a queue
is also called First in First Out (FIFO).
• Add and item in a queue
• Remove an item from the queue
• Last In First Out queue
• Remove an item from the queue
• Add more than 1 item in a queue
• Add and item in a LIFO queue
32
counter, enumerate
• Python Counter takes in input a list, tuple, dictionary, string, which
are all iterable objects, and it will give you output that will have the
count of each element.
• counter()
• enumerate()
• enumerate a dictionary
33
type() and isinstance()
• Python has a built-in function called type() that helps you find the
class type of the variable given as input
34
Homework Assignment
• Use python range function to output nine-nine multiplication table
• Use python output Fibonacci-Series by using generators and yield
function
• Output: Fibonacci-Series: [0,1,1,2,3,5,8]
• Sorting queue
35