SlideShare a Scribd company logo
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 (20)

PDF
TensorFlow and Keras: An Overview
Poo Kuan Hoong
 
PDF
Large Scale Deep Learning with TensorFlow
Jen Aman
 
PDF
TensorFlow 101
Raghu Rajah
 
PPTX
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017
Ashish Bansal
 
PPTX
Tensorflow - Intro (2017)
Alessio Tonioni
 
PPTX
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
Simplilearn
 
PDF
Introduction To TensorFlow
Spotle.ai
 
PDF
Deep learning with TensorFlow
Ndjido Ardo BAR
 
PPTX
Big data app meetup 2016-06-15
Illia Polosukhin
 
PDF
Introduction to Neural Networks in Tensorflow
Nicholas McClure
 
PPTX
TensorFlow in Context
Altoros
 
PPTX
Tensorflow
marwa Ayad Mohamed
 
PPTX
Tensorflow internal
Hyunghun Cho
 
PDF
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...
Databricks
 
PPTX
Neural networks and google tensor flow
Shannon McCormick
 
PPTX
TensorFrames: Google Tensorflow on Apache Spark
Databricks
 
PDF
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
Kendall
 
PPTX
Deep learning with Tensorflow in R
mikaelhuss
 
PDF
Spark Meetup TensorFrames
Jen Aman
 
PDF
Introduction to TensorFlow
Ralph Vincent Regalado
 
TensorFlow and Keras: An Overview
Poo Kuan Hoong
 
Large Scale Deep Learning with TensorFlow
Jen Aman
 
TensorFlow 101
Raghu Rajah
 
Tensorflow 101 @ Machine Learning Innovation Summit SF June 6, 2017
Ashish Bansal
 
Tensorflow - Intro (2017)
Alessio Tonioni
 
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
Simplilearn
 
Introduction To TensorFlow
Spotle.ai
 
Deep learning with TensorFlow
Ndjido Ardo BAR
 
Big data app meetup 2016-06-15
Illia Polosukhin
 
Introduction to Neural Networks in Tensorflow
Nicholas McClure
 
TensorFlow in Context
Altoros
 
Tensorflow
marwa Ayad Mohamed
 
Tensorflow internal
Hyunghun Cho
 
Data Science and Deep Learning on Spark with 1/10th of the Code with Roope As...
Databricks
 
Neural networks and google tensor flow
Shannon McCormick
 
TensorFrames: Google Tensorflow on Apache Spark
Databricks
 
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
Kendall
 
Deep learning with Tensorflow in R
mikaelhuss
 
Spark Meetup TensorFrames
Jen Aman
 
Introduction to TensorFlow
Ralph Vincent Regalado
 

Similar to Intro to Python (20)

PPTX
GDG Helwan Introduction to python
Mohamed Hegazy
 
PPT
Introduction to Python For Diploma Students
SanjaySampat1
 
PPTX
Python for dummies
Roberto Stefanetti
 
PPTX
MODULE 1.pptx
KPDDRAVIDIAN
 
PPTX
Introduction to Programming.pptx ok ok ok
846Sarthakpandey
 
PDF
Python Novice to Ninja
Al Sayed Gamal
 
PDF
Blueprints: Introduction to Python programming
Bhalaji Nagarajan
 
PPT
Python ppt
Mohita Pandey
 
DOCX
A Introduction Book of python For Beginners.docx
kumarrabinderkumar77
 
PPTX
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
PPTX
Welcome to python workshop
Mukul Kirti Verma
 
PPTX
PYTHON PROGRAMMING.pptx
swarna627082
 
PPTX
Python-Mastering-the-Language-of-Data-Science.pptx
dmdHaneef
 
PDF
Learn to Code with MIT App Inventor ( PDFDrive ).pdf
NemoPalleschi
 
PPTX
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
PPTX
Python programming
Ganesh Bhosale
 
ODP
Hands on Session on Python
Sumit Raj
 
PPTX
Introduction to python.pptx
pcjoshi02
 
PDF
Free Complete Python - A step towards Data Science
RinaMondal9
 
PPTX
Lecture Introduction to Python 2024.pptx
fgbcssarl
 
GDG Helwan Introduction to python
Mohamed Hegazy
 
Introduction to Python For Diploma Students
SanjaySampat1
 
Python for dummies
Roberto Stefanetti
 
MODULE 1.pptx
KPDDRAVIDIAN
 
Introduction to Programming.pptx ok ok ok
846Sarthakpandey
 
Python Novice to Ninja
Al Sayed Gamal
 
Blueprints: Introduction to Python programming
Bhalaji Nagarajan
 
Python ppt
Mohita Pandey
 
A Introduction Book of python For Beginners.docx
kumarrabinderkumar77
 
Introduction to Python Programming .pptx
NaynaSagarDahatonde
 
Welcome to python workshop
Mukul Kirti Verma
 
PYTHON PROGRAMMING.pptx
swarna627082
 
Python-Mastering-the-Language-of-Data-Science.pptx
dmdHaneef
 
Learn to Code with MIT App Inventor ( PDFDrive ).pdf
NemoPalleschi
 
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Python programming
Ganesh Bhosale
 
Hands on Session on Python
Sumit Raj
 
Introduction to python.pptx
pcjoshi02
 
Free Complete Python - A step towards Data Science
RinaMondal9
 
Lecture Introduction to Python 2024.pptx
fgbcssarl
 
Ad

Recently uploaded (20)

PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Tally software_Introduction_Presentation
AditiBansal54083
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Ad

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