SlideShare a Scribd company logo
1 of 29
DEV SUMMIT 2017 EXTENDED
Introduction to Python 3
Mohamed Hegazy
R&D Engineer
.PY
DEV SUMMIT 2017 EXTENDED
What is python . WIKI
• Python is a widely used high-level programming language used for general-
purpose programming. An interpreted language, Python has a design philosophy
which emphasizes code readability (notably using whitespace indentation to
delimit code blocks rather than curly braces or keywords), and a syntax which
allows programmers to express concepts in fewer lines of code than possible in
languages such as C++ or Java.The language provides constructs intended to
enable writing clear programs on both a small and large scale.
• A scripting language is a subset of programming language that is used to produce
scripts, which are sets of instructions that automate tasks that would otherwise
be performed manually by a human. Of course, these "tasks" are essentially a
human giving instructions to a machine, as described above, so you could say that
a script instructs a machine on what instructions to give itself that a human
would otherwise give.
2
DEV SUMMIT 2017 EXTENDED
Agenda
1. Python Installation
2. Syntax
3. Objects
4. Conditions and Loops
5. Classes and Functions
6. Error Handling
7. Modules
8. Working with Files
9. Working With database
3
DEV SUMMIT 2017 EXTENDED
Python Installation
• Perquisites on windows.
• Download python for windows
https://www.python.org/downloads/windows/
• For this session we will use 3.6.0
• Download python for mac (for latest Update)
https://www.python.org/downloads/mac-osx/
• In Mac and Lunix its installed by default
• To run python use CMD -> Python
• Editors such as Pycharm , eclipse + pydev, Sublime, Aptana
4
DEV SUMMIT 2017 EXTENDED
Everything is an Object
• Id, type, value
• Id is unique identifier for the object
• Type is the class it is initialized from
• Value is the content
5
DEV SUMMIT 2017 EXTENDED
Syntax
• Python doesn’t use “int, double, string, var, etc…” as variable type.
Instead, python creates everything as an object and based on
assignment it calls the class and initialize
• Python doesn’t use “;”. It depends on whitespaces and indentation.
Wrong indentation means buggy code. P.S: you either use
whitespaces or tab.
• Example
• A = 0
• a,b,c = 0,1,”Hello”
6
DEV SUMMIT 2017 EXTENDED
Syntax Mutable vs immutable
• Number , Strings, Tuples are immutable.
• List , Dictionaries , other objects depending upon implementation.
7
DEV SUMMIT 2017 EXTENDED
Syntax
• When changing a value of an Immutable object. the reference of
value changes.
• Example
x=2
Id(x)
>>> 1231312
x=3
Id(x)
>>> 2349233
x=2
Id(x)
>>> 1231312
8
DEV SUMMIT 2017 EXTENDED
Syntax
• The variables created are stored in ram for later garbage collection to
pick it up. However there is a “faster” way using “del” keyword to
delete that variable
9
DEV SUMMIT 2017 EXTENDED
Syntax
• However, we can figure out the type of object with 2 ways.
1- the value
2- type(x) <- this will print out <class ‘str’>
a. it can be used to if want to make sure that the values are of certain type.
Note that print by default adds new line, it can be manipulated using
print (‘----’, end=‘’) <- end here will add zero space instead of newline
10
DEV SUMMIT 2017 EXTENDED
Syntax Dealing with Strings
• Strings can be used for chars and strings.
• Using single-quoted or double quoted is the same
• Since there is no char support, the work around is substring.
var1 = ‘hello world’
var2 = ‘python programming’
print(var1[0]) -> h
print(var2[8:]) -> programming
0 1 2 3 4
H E L L O
-5 -4 -3 -2 -1
11
DEV SUMMIT 2017 EXTENDED
Syntax Dealing with Strings
• r’string writenn here’ will result in string writenn here
• ‘String writenn here’ ->
• ‘My name is {} ‘. Format(“Mohamed hegazy”)
• My name is Mohamed hegazy
string write
n here
12
var = "hello World"
print(var[0]) # Single Char
print(var[5:]) # Range
print(var[:6]) # Range
print(var[:-1]) # Range
print("W" in var)
print('helntnn')
print(r'helntnn')
DEV SUMMIT 2017 EXTENDED
Syntax (*args and **kwargs)
• *Args prints data as tuple (remember tuple is immutable)
• **Kwargs prints and saves data as dictionary (remember dictionary is
mutable)
13
DEV SUMMIT 2017 EXTENDED
Conditions
• If condition doesn’t have “()”
Ex. If a<b:
print(‘a is bigger than b’)
• Python doesn’t support the switch statement, however there is a work
around.
If v == ‘----’:
Print(“this is first one”)
elif v == ‘qwdqwdqq’:
print(“this is the second one”)
else:
print(“this is not in the switch case”)
and, or, not
14
DEV SUMMIT 2017 EXTENDED
Loops
• While loop.
• For loop
For i = 0, i<x , i++ -> it doesn’t exist
15
while i < 10:
print(i)
i += i
for line in cursor.fetchall():
print(line, end=" ")
DEV SUMMIT 2017 EXTENDED
Defining Classes and functions
• Class is how to create your own object
• Class is a blueprint for an object
• Object is instance of a class
• Classes can be used in inheritance
16
DEV SUMMIT 2017 EXTENDED
Defining Classes
17
DEV SUMMIT 2017 EXTENDED
Defining Classes
18
if __name__ == '__main__':main()
DEV SUMMIT 2017 EXTENDED
Error Handling
• Python error handling, Mitigating the app from crashing on error.
• Raising Exception
• Raise is used to create custom exceptions
• Ex. Have a .docx file and .txt file. Mainly, my data is stored in .txt file,
therefore I created a custom exception to notify the user to only use. Txt file
19
DEV SUMMIT 2017 EXTENDED
Error Handling
20
DEV SUMMIT 2017 EXTENDED
Power of Yield
• Yield is like the return . However, yield can be used to return the
argument and continue the loop
• def __iter__(self):
i = self.start
while(i <= self.stop):
yield i
i += self.step
21
DEV SUMMIT 2017 EXTENDED
modules
• Modules are used to add “extension/inheritance” .
• Basic Python support limited functions comparing to modules.
• Using PIP and Easy_install
• Ex. Adding web functionality to python .
• Import Django
• Import sqlite3
Ex.
Import Django (as d
Django.Version
pinrt(Django.get_version())
22
DEV SUMMIT 2017 EXTENDED
File I/O
• Read from file
• Write to file
• Read from file binary
• Write to file binary
• Buffer read , Buffer write
• appending
23
DEV SUMMIT 2017 EXTENDED
File I/O
24
DEV SUMMIT 2017 EXTENDED
Database
• CRUD Operation IN Python combining it with try/catch , class,
functions.
25
DEV SUMMIT 2017 EXTENDED
Database
26
DEV SUMMIT 2017 EXTENDED
Database
27
DEV SUMMIT 2017 EXTENDED
Database
28
DEV SUMMIT 2017 EXTENDED
Thank You For Attending
Any Questions ?
29

More Related Content

What's hot

TensorFlow and Keras: An Overview
TensorFlow and Keras: An OverviewTensorFlow and Keras: An Overview
TensorFlow and Keras: An OverviewPoo Kuan Hoong
 
Large Scale Deep Learning with TensorFlow
Large Scale Deep Learning with TensorFlow Large Scale Deep Learning with TensorFlow
Large Scale Deep Learning with TensorFlow Jen Aman
 
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017Ashish Bansal
 
Tensorflow - Intro (2017)
Tensorflow - Intro (2017)Tensorflow - Intro (2017)
Tensorflow - Intro (2017)Alessio Tonioni
 
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...Simplilearn
 
Introduction To TensorFlow
Introduction To TensorFlowIntroduction To TensorFlow
Introduction To TensorFlowSpotle.ai
 
Deep learning with TensorFlow
Deep learning with TensorFlowDeep learning with TensorFlow
Deep learning with TensorFlowNdjido Ardo BAR
 
Big data app meetup 2016-06-15
Big data app meetup 2016-06-15Big data app meetup 2016-06-15
Big data app meetup 2016-06-15Illia Polosukhin
 
Introduction to Neural Networks in Tensorflow
Introduction to Neural Networks in TensorflowIntroduction to Neural Networks in Tensorflow
Introduction to Neural Networks in TensorflowNicholas McClure
 
TensorFlow in Context
TensorFlow in ContextTensorFlow in Context
TensorFlow in ContextAltoros
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internalHyunghun Cho
 
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...Databricks
 
Neural networks and google tensor flow
Neural networks and google tensor flowNeural networks and google tensor flow
Neural networks and google tensor flowShannon McCormick
 
TensorFrames: Google Tensorflow on Apache Spark
TensorFrames: Google Tensorflow on Apache SparkTensorFrames: Google Tensorflow on Apache Spark
TensorFrames: Google Tensorflow on Apache SparkDatabricks
 
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
Intro to TensorFlow and PyTorch Workshop at Tubular LabsIntro to TensorFlow and PyTorch Workshop at Tubular Labs
Intro to TensorFlow and PyTorch Workshop at Tubular LabsKendall
 
Deep learning with Tensorflow in R
Deep learning with Tensorflow in RDeep learning with Tensorflow in R
Deep learning with Tensorflow in Rmikaelhuss
 
Spark Meetup TensorFrames
Spark Meetup TensorFramesSpark Meetup TensorFrames
Spark Meetup TensorFramesJen Aman
 

What's hot (20)

TensorFlow and Keras: An Overview
TensorFlow and Keras: An OverviewTensorFlow and Keras: An Overview
TensorFlow and Keras: An Overview
 
Large Scale Deep Learning with TensorFlow
Large Scale Deep Learning with TensorFlow Large Scale Deep Learning with TensorFlow
Large Scale Deep Learning with TensorFlow
 
TensorFlow 101
TensorFlow 101TensorFlow 101
TensorFlow 101
 
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017
 
Tensorflow - Intro (2017)
Tensorflow - Intro (2017)Tensorflow - Intro (2017)
Tensorflow - Intro (2017)
 
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
 
Introduction To TensorFlow
Introduction To TensorFlowIntroduction To TensorFlow
Introduction To TensorFlow
 
Deep learning with TensorFlow
Deep learning with TensorFlowDeep learning with TensorFlow
Deep learning with TensorFlow
 
Big data app meetup 2016-06-15
Big data app meetup 2016-06-15Big data app meetup 2016-06-15
Big data app meetup 2016-06-15
 
Introduction to Neural Networks in Tensorflow
Introduction to Neural Networks in TensorflowIntroduction to Neural Networks in Tensorflow
Introduction to Neural Networks in Tensorflow
 
TensorFlow in Context
TensorFlow in ContextTensorFlow in Context
TensorFlow in Context
 
Tensorflow
TensorflowTensorflow
Tensorflow
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
 
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...
 
Neural networks and google tensor flow
Neural networks and google tensor flowNeural networks and google tensor flow
Neural networks and google tensor flow
 
TensorFrames: Google Tensorflow on Apache Spark
TensorFrames: Google Tensorflow on Apache SparkTensorFrames: Google Tensorflow on Apache Spark
TensorFrames: Google Tensorflow on Apache Spark
 
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
Intro to TensorFlow and PyTorch Workshop at Tubular LabsIntro to TensorFlow and PyTorch Workshop at Tubular Labs
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
 
Deep learning with Tensorflow in R
Deep learning with Tensorflow in RDeep learning with Tensorflow in R
Deep learning with Tensorflow in R
 
Spark Meetup TensorFrames
Spark Meetup TensorFramesSpark Meetup TensorFrames
Spark Meetup TensorFrames
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlow
 

Similar to Intro to Python

GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to pythonMohamed Hegazy
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IDUSPviz
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxGaneshRaghu4
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptUdhayaKumar175069
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in Cummeafruz
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functionsray143eddie
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptAlefya1
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.pptRehnawilson1
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP PerspectiveBarry Jones
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptJoshCasas1
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
Cs4hs2008 track a-programming
Cs4hs2008 track a-programmingCs4hs2008 track a-programming
Cs4hs2008 track a-programmingRashi Agarwal
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unitKotresh Munavallimatt
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxRohitKumar639388
 

Similar to Intro to Python (20)

GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to python
 
Python ppt
Python pptPython ppt
Python ppt
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptx
 
Python_intro.ppt
Python_intro.pptPython_intro.ppt
Python_intro.ppt
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Python Module-1.1.pdf
Python Module-1.1.pdfPython Module-1.1.pdf
Python Module-1.1.pdf
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Unit1 pps
Unit1 ppsUnit1 pps
Unit1 pps
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Cs4hs2008 track a-programming
Cs4hs2008 track a-programmingCs4hs2008 track a-programming
Cs4hs2008 track a-programming
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unit
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 

Recently uploaded (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Intro to Python

  • 1. DEV SUMMIT 2017 EXTENDED Introduction to Python 3 Mohamed Hegazy R&D Engineer .PY
  • 2. DEV SUMMIT 2017 EXTENDED What is python . WIKI • Python is a widely used high-level programming language used for general- purpose programming. An interpreted language, Python has a design philosophy which emphasizes code readability (notably using whitespace indentation to delimit code blocks rather than curly braces or keywords), and a syntax which allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java.The language provides constructs intended to enable writing clear programs on both a small and large scale. • A scripting language is a subset of programming language that is used to produce scripts, which are sets of instructions that automate tasks that would otherwise be performed manually by a human. Of course, these "tasks" are essentially a human giving instructions to a machine, as described above, so you could say that a script instructs a machine on what instructions to give itself that a human would otherwise give. 2
  • 3. DEV SUMMIT 2017 EXTENDED Agenda 1. Python Installation 2. Syntax 3. Objects 4. Conditions and Loops 5. Classes and Functions 6. Error Handling 7. Modules 8. Working with Files 9. Working With database 3
  • 4. DEV SUMMIT 2017 EXTENDED Python Installation • Perquisites on windows. • Download python for windows https://www.python.org/downloads/windows/ • For this session we will use 3.6.0 • Download python for mac (for latest Update) https://www.python.org/downloads/mac-osx/ • In Mac and Lunix its installed by default • To run python use CMD -> Python • Editors such as Pycharm , eclipse + pydev, Sublime, Aptana 4
  • 5. DEV SUMMIT 2017 EXTENDED Everything is an Object • Id, type, value • Id is unique identifier for the object • Type is the class it is initialized from • Value is the content 5
  • 6. DEV SUMMIT 2017 EXTENDED Syntax • Python doesn’t use “int, double, string, var, etc…” as variable type. Instead, python creates everything as an object and based on assignment it calls the class and initialize • Python doesn’t use “;”. It depends on whitespaces and indentation. Wrong indentation means buggy code. P.S: you either use whitespaces or tab. • Example • A = 0 • a,b,c = 0,1,”Hello” 6
  • 7. DEV SUMMIT 2017 EXTENDED Syntax Mutable vs immutable • Number , Strings, Tuples are immutable. • List , Dictionaries , other objects depending upon implementation. 7
  • 8. DEV SUMMIT 2017 EXTENDED Syntax • When changing a value of an Immutable object. the reference of value changes. • Example x=2 Id(x) >>> 1231312 x=3 Id(x) >>> 2349233 x=2 Id(x) >>> 1231312 8
  • 9. DEV SUMMIT 2017 EXTENDED Syntax • The variables created are stored in ram for later garbage collection to pick it up. However there is a “faster” way using “del” keyword to delete that variable 9
  • 10. DEV SUMMIT 2017 EXTENDED Syntax • However, we can figure out the type of object with 2 ways. 1- the value 2- type(x) <- this will print out <class ‘str’> a. it can be used to if want to make sure that the values are of certain type. Note that print by default adds new line, it can be manipulated using print (‘----’, end=‘’) <- end here will add zero space instead of newline 10
  • 11. DEV SUMMIT 2017 EXTENDED Syntax Dealing with Strings • Strings can be used for chars and strings. • Using single-quoted or double quoted is the same • Since there is no char support, the work around is substring. var1 = ‘hello world’ var2 = ‘python programming’ print(var1[0]) -> h print(var2[8:]) -> programming 0 1 2 3 4 H E L L O -5 -4 -3 -2 -1 11
  • 12. DEV SUMMIT 2017 EXTENDED Syntax Dealing with Strings • r’string writenn here’ will result in string writenn here • ‘String writenn here’ -> • ‘My name is {} ‘. Format(“Mohamed hegazy”) • My name is Mohamed hegazy string write n here 12 var = "hello World" print(var[0]) # Single Char print(var[5:]) # Range print(var[:6]) # Range print(var[:-1]) # Range print("W" in var) print('helntnn') print(r'helntnn')
  • 13. DEV SUMMIT 2017 EXTENDED Syntax (*args and **kwargs) • *Args prints data as tuple (remember tuple is immutable) • **Kwargs prints and saves data as dictionary (remember dictionary is mutable) 13
  • 14. DEV SUMMIT 2017 EXTENDED Conditions • If condition doesn’t have “()” Ex. If a<b: print(‘a is bigger than b’) • Python doesn’t support the switch statement, however there is a work around. If v == ‘----’: Print(“this is first one”) elif v == ‘qwdqwdqq’: print(“this is the second one”) else: print(“this is not in the switch case”) and, or, not 14
  • 15. DEV SUMMIT 2017 EXTENDED Loops • While loop. • For loop For i = 0, i<x , i++ -> it doesn’t exist 15 while i < 10: print(i) i += i for line in cursor.fetchall(): print(line, end=" ")
  • 16. DEV SUMMIT 2017 EXTENDED Defining Classes and functions • Class is how to create your own object • Class is a blueprint for an object • Object is instance of a class • Classes can be used in inheritance 16
  • 17. DEV SUMMIT 2017 EXTENDED Defining Classes 17
  • 18. DEV SUMMIT 2017 EXTENDED Defining Classes 18 if __name__ == '__main__':main()
  • 19. DEV SUMMIT 2017 EXTENDED Error Handling • Python error handling, Mitigating the app from crashing on error. • Raising Exception • Raise is used to create custom exceptions • Ex. Have a .docx file and .txt file. Mainly, my data is stored in .txt file, therefore I created a custom exception to notify the user to only use. Txt file 19
  • 20. DEV SUMMIT 2017 EXTENDED Error Handling 20
  • 21. DEV SUMMIT 2017 EXTENDED Power of Yield • Yield is like the return . However, yield can be used to return the argument and continue the loop • def __iter__(self): i = self.start while(i <= self.stop): yield i i += self.step 21
  • 22. DEV SUMMIT 2017 EXTENDED modules • Modules are used to add “extension/inheritance” . • Basic Python support limited functions comparing to modules. • Using PIP and Easy_install • Ex. Adding web functionality to python . • Import Django • Import sqlite3 Ex. Import Django (as d Django.Version pinrt(Django.get_version()) 22
  • 23. DEV SUMMIT 2017 EXTENDED File I/O • Read from file • Write to file • Read from file binary • Write to file binary • Buffer read , Buffer write • appending 23
  • 24. DEV SUMMIT 2017 EXTENDED File I/O 24
  • 25. DEV SUMMIT 2017 EXTENDED Database • CRUD Operation IN Python combining it with try/catch , class, functions. 25
  • 26. DEV SUMMIT 2017 EXTENDED Database 26
  • 27. DEV SUMMIT 2017 EXTENDED Database 27
  • 28. DEV SUMMIT 2017 EXTENDED Database 28
  • 29. DEV SUMMIT 2017 EXTENDED Thank You For Attending Any Questions ? 29