Python for dummies

RobertoStefanetti 997 views 42 slides Mar 18, 2019
Slide 1
Slide 1 of 42
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42

About This Presentation

Python for dummies


Slide Content

Roberto Stefanetti, MVP Business Applications Microsoft Education Influencer https :// robertostefanettinavblog.com Python for Dummies 1969-2019 “Fortran with Apollo 11 and Python for Mission to Mars” Roberto Stefanetti

WHAT IS PYTHON ? PYTHON ? https://www.python.org Python is an open source programming language that was made to be easy-to-read and powerful . A Dutch programmer named  Guido van Rossum  made Python in 1991. He named it after the television show Monty Python's Flying Circus

Python Diffusion

PYTHON IS USED IN.. Python is used in... a lot of institutions ! NASA, Facebook, Google, Mozilla, Yahoo, Dropbox, IBM, Youtube, iRobot, Maya, Paint apps etc. etc. … these “ Giants ” use Python in their “ CORE products ” and services!

DOWNLOAD PYTHON Python can be run on Apache ( Linux ) and IIS ( Windows ) and in Visual Studio Code (as Python Extension) Python for Windows Download   from https ://www.python.org/downloads/windows/

PYTHON for Visual Studio Code Python can be run also in Visual Studio Code (as Python Extension).. Nice for Business Central Developers…

About Python Python is: Programming language Scripting language Interpreted language (called AS IS) Open Source (by Design) Born between 1980-1990

Python is for Python is for: “A lot of implementations” Desktop App, Mobile App, Web App AI & ML Data Science IoT (Internet of Things) Interfaces…. ..and many other things

Python can manage Python can manage: UI Databases Calculations Graphics Scripting & Programming Authentications & protocols

Phyton Technology Python Technology Object oriented language (polymorph, inheritance, overriding etc.) Interpreted (copy and run fast!…) Clear and simple code Language is expandable with other sub languages (ex: Flask module) Extensible (libraries) #import…. modules

Python Editor Python Editor SHELL

Source Code “.py” and “.pyc” Python Source Code Extension code is “ .py ”  Python Code Translated to byte code (complied to “ .pyc ”)  Compiled Python On Virtual Machine  Written and compiled  but interpreted

Syntax Syntax Python Identifier : a name used to identify a variable, function, class, module or other objects. An Identifier start with a letter A..Z or a..z or an _ ( underscore ) NO punctuation chars : @, $, % etc., is CASE SENSITIVE NO Braches for blocks (only indentation) # is a comment Python u se ‘, ‘’, ‘’’ quote to define strings if Condition: Statement = ‘test’ e lse: OtherStatement = ‘test2’

Data Types Data Types Major Python data types: String - ‘’ & “” List - [1,2,’aa’,True] Tuple - (34, 3.4, ‘aa’, True)  immutable Set/frozenset - set(1,2, ‘aa’,True) Hash Dictionary - {‘k1’:1, ‘k2’:False}  Groups of Keys and values

Strings Strings String: a contiguous set of chars in quotation marks. Subset string : taken using slice operator ([], [:]) + = concatenation operator * = repetition operator

Lists Lists Lists: separate by commas and enclosed in brackets [] (like C,C# arrays) Data Values : you can access to lists data values using with slice operators + = concatenation operator * = repetition operator

Operators Python Operators (various) - Arithmetic - Relational - Conditional - Logical - Bitwise - Assignment - Special

Operators Comparison operators

Conditionals Conditionals Statements If statement (boolean expression) If else statement (with optional else) Nested if statements (if nested in other if..)

Loops Types of loops While loop For loop

Functions Functions A function is an organized and “ reusable ” block of code. Many Built-in Functions are already available (ex: print ) You can create your “user functions” A Function block start with def followed b y name and () def  my_function( fname ):    print (fname +  " Refsnes" ) my_function( "Emil" ) my_function( "Tobias" ) my_function( "Linus" ) def  my_function():    print ( "Hello from a function" ) my_function()

Functions Functions - return value & recursion def tri_recursion(k):    if (k> ):     result = k+tri_recursion(k- 1 )     print(result)    else :     result =     return  result print( "\n\nRecursion Example Results" ) tri_recursion( 6 ) def  my_function(x):    return   5  * x print (my_function( 3 )) print (my_function( 5 )) print (my_function( 9 ))

Function with Description Function with Descriptions cmp (listA, listB )  compare elements len(list)  total length max(list)  max & Min m in(list) list(seq)  convert a tuple into a list

Modules Python Module?  file containing python statements (DLL like) “Divide and impera”  with modules Module is a object with a lot of functions (like a function server or function package) You can “ Import Modules ”

Inheritance Inheritance ? > Sure, you can create a parent class and a child class class   Person :    def  __init__(self, fname, lname):     self.firstname = fname     self.lastname = lname    def  printname(self):     print(self.firstname, self.lastname) #Use the Person class to create an object, and then execute the printname method: x = Person( "John" ,  "Doe" ) x.printname() class   Student (Person):    pass x = Student( "Mike" ,  "Olsen" ) x.printname()

Try-Except Try-Except The   try  block lets you test a block of code for errors The   except  block lets you handle the error The   finally  block lets you execute code, regardless of the result of the try- and except blocks try :    print (x) except :    print ( "An exception occurred" )

Json ( Convert from JSON to Python & Vice-versa ) Json import  json # some JSON: x =   '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result is a Python dictionary: print (y[ "age" ]) Convert from JSON to Python: Convert from Python to JSON: import  json # a Python object (dict): x = {    "name" :  "John" ,    "age" :  30 ,    "city" :  "New York" } # convert into JSON: y = json.dumps(x) # the result is a JSON string: print (y)

Install “.pip” modules (Python installer packages) Install “.pip” modules (Python Modules: “DLL” like) Example: install “Django” module (Angular) “pip install Django”

Import modules Import modules normal import (import entire module with ALL properties) from import (import required properties from a module.. ..not all module’s features are available ..example: only a function from a module)

PYTHON LIMITATIONS PYTHON LIMITATIONS Performance (interpreted) Not Mobile: not available in mobile applications! NO, not true to date …now you can have! https://www.ongraph.com/a-list-of-top-10-python-frameworks-for-app-development /

PYTHON BEST MODULES WE CAN HAVE PYTHON MODULES OF ANY TYPES Below a short list: Mongo SQLAlchemy Wx Phyton Twisted Mathplotlib Requests Beautiful Soap Pygame Fabric http://blog.stoneriverelearning.com/20-great-python-libraries-you-must-know /

PYTHON BEST FRAMEWORKS BEST FRAMEWORS Below a short list: Django Flask Web2py Pandas Bottle Falcon TurboGears NumPy https ://www.ongraph.com/a-list-of-top-10-python-frameworks-for-app-development /

FLASK (for Python) FLASK Flask is a micro-web framework , thus does not need particular tools or libraries. It built-in with development server and support for unit testing. This Unicode based platform supports RESTFUL ask for dispatching and is broadly reported for application developers to begin . Course: Great Free Course @Harvard.edu   https:// online-learning.harvard.edu/course/cs50s-web-programming-python-and-javascript?delta=0 http://flask.pocoo.org/

FLASK (for Python) Dev Environment FLASK Dev Environment - Install Install Windows Flask Dev Env 4 Steps: - Install Python -Install Pip -Install VirtualEnv -Install VirtualEnvWrapper-win http ://timmyreilly.azurewebsites.net/python-flask-windows-development-environment-setup /

FLASK (for Python) Dev Environment FLASK Dev Environment USAGE 7 Steps: -Make a Virtual Environment -Connect our project with our Environment -Set Project Directory -Deactivate -Workon -Pip Install -Flask !

FLASK IS FUN! FLASK IS FUN! http ://flask.pocoo.org / https://realpython.com/flask-by-example-part-1-project-setup / http://timmyreilly.azurewebsites.net/python-flask-windows-development-environment-setup / https:// medium.freecodecamp.org/how-to-build-a-web-application-using-flask-and-deploy-it-to-the-cloud-3551c985e492

FLASK DEMO: TIC-TAC-TOC FLASK TIC-TAC-TOC Tic Tac Toe using Flask framework and Angular. AI uses the minimax algorithm to calculate moves . https :// github.com/Buuntu/minimax-algorithm Angular + Python + Flask — Full stack https ://medium.com/@ balramchavan/angular-python-flask-full-stack-demo-27192b8de1a3

FLASK DEMO: TIC-TAC-TOC FLASK TIC-TAC-TOC – PART OF CODE

EXAMPLE: CONSUMING a Dynamics 365 Business Central APIs from PYTHON https://robertostefanettinavblog.com/2019/03/09/consuming-business-central-apis-from-python /

EXAMPLE: CONSUMING a Dynamics 365 Business Central APIs from PYTHON

Python & Flask – Best L inks Python.org https ://www.python.org / Python Tutorial https://www.w3schools.com/python / Flask Tutorial (best Web micro-framework) https:// github.com/rstefanetti/SPGISummer2018-FlaskTutorial https:// medium.freecodecamp.org/how-to-build-a-web-application-using-flask-and-deploy-it-to-the-cloud-3551c985e492 https:// www.linkedin.com/learning/building-web-apis-with-flask?trk=search-cluster_flagship_learning http://timmyreilly.azurewebsites.net/python-flask-windows-development-environment-setup / Example of System Integrations with Python https://robertostefanettinavblog.com/2019/03/09/consuming-business-central-apis-from-python /

THANKS FOR WATCHING ! Roberto Stefanetti, MVP Business Applications Microsoft Education Influencer https :// robertostefanettinavblog.com