Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

of

Intro to Python Slide 1 Intro to Python Slide 2 Intro to Python Slide 3 Intro to Python Slide 4 Intro to Python Slide 5 Intro to Python Slide 6 Intro to Python Slide 7 Intro to Python Slide 8 Intro to Python Slide 9 Intro to Python Slide 10 Intro to Python Slide 11 Intro to Python Slide 12 Intro to Python Slide 13 Intro to Python Slide 14 Intro to Python Slide 15 Intro to Python Slide 16 Intro to Python Slide 17 Intro to Python Slide 18 Intro to Python Slide 19 Intro to Python Slide 20 Intro to Python Slide 21 Intro to Python Slide 22 Intro to Python Slide 23 Intro to Python Slide 24 Intro to Python Slide 25 Intro to Python Slide 26 Intro to Python Slide 27 Intro to Python Slide 28 Intro to Python Slide 29
Upcoming SlideShare
20150306 파이썬기초 IPython을이용한프로그래밍_이태영
Next
Download to read offline and view in fullscreen.

4 Likes

Share

Download to read offline

Intro to Python

Download to read offline

introduction to Python by Mohamed Hegazy , in this slides you will find some code samples , these slides first presented in TensorFlow Dev Summit 2017 Extended by GDG Helwan

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Intro to Python

  1. 1. DEV SUMMIT 2017 EXTENDED Introduction to Python 3 Mohamed Hegazy R&D Engineer .PY
  2. 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. 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. 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. 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. 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. 7. DEV SUMMIT 2017 EXTENDED Syntax Mutable vs immutable • Number , Strings, Tuples are immutable. • List , Dictionaries , other objects depending upon implementation. 7
  8. 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. 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. 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. 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. 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. 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. 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. 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. 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. 17. DEV SUMMIT 2017 EXTENDED Defining Classes 17
  18. 18. DEV SUMMIT 2017 EXTENDED Defining Classes 18 if __name__ == '__main__':main()
  19. 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. 20. DEV SUMMIT 2017 EXTENDED Error Handling 20
  21. 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. 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. 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. 24. DEV SUMMIT 2017 EXTENDED File I/O 24
  25. 25. DEV SUMMIT 2017 EXTENDED Database • CRUD Operation IN Python combining it with try/catch , class, functions. 25
  26. 26. DEV SUMMIT 2017 EXTENDED Database 26
  27. 27. DEV SUMMIT 2017 EXTENDED Database 27
  28. 28. DEV SUMMIT 2017 EXTENDED Database 28
  29. 29. DEV SUMMIT 2017 EXTENDED Thank You For Attending Any Questions ? 29
  • seswaran

    May. 1, 2017
  • jesusliebanalosada

    Mar. 22, 2017
  • mabdelaal86

    Feb. 26, 2017
  • bunkertor

    Feb. 26, 2017

introduction to Python by Mohamed Hegazy , in this slides you will find some code samples , these slides first presented in TensorFlow Dev Summit 2017 Extended by GDG Helwan

Views

Total views

779

On Slideshare

0

From embeds

0

Number of embeds

2

Actions

Downloads

15

Shares

0

Comments

0

Likes

4

×