first tool python
play

First Tool: Python! Introduction to python programming - PowerPoint PPT Presentation

First Tool: Python! Introduction to python programming Gholamhossein Tavasoli @ ZNU First Tool: Python! Python Programming Language Python Programming Language Created in 1991 by Guido van Rossum Python Cro ross Platform Pro rogramming


  1. First Tool: Python! Introduction to python programming Gholamhossein Tavasoli @ ZNU

  2. First Tool: Python!

  3. Python Programming Language

  4. Python Programming Language Created in 1991 by Guido van Rossum

  5. Python Cro ross Platform Pro rogramming Lan angua uage Programming Language Created in 1991 by Guido van Rossum

  6. Python Cro ross Platform Pro rogramming Lan angua uage Programming Language Created in 1991 by Guido van Rossum Freely Usable Even for Commercial Use

  7. 6 Lessons from Dropbox o One Million Files Saved Every 15 minutes (2011) o Use Pyt ython o 99.9 % of their code is in Python o server backend o desktop client o website controller logic o API backend o analytics o Can't use Python on the Android due to memory constraints o Runs on a single code base using Python. Dropbox runs on Win indows, Mac, Lin inux using tools like PyObjs, WxPython, types, py2exe, py2app, PyWin32.

  8. 6 Lessons from Dropbox o Pros o Developers talk to each other and express ideas in Python o Easy to learn, easy to read, easy to write, easy for new people to pick up. o Cons o OK, it can use too much memory and be too slow. o Coding in a mixed environment of Python and C creates problems o Memory fragmentation issues are reason why scripting languages may not be a good idea for long running processes

  9. 6 Lessons from Dropbox o Just W Work Baby o Shouldn't matter what file system you are on, what OS you are using, what applications you are using. The product should always just work. o Python helped them iterate fast through all the different error cases they experienced on the wide variety of platforms they support.

  10. 6 Lessons from Dropbox o Release Early o Code something in a day and release it. Python makes that easy.

  11. 6 Lessons from Dropbox o Use C f for In Inner Loops - Optimizing CPU is easy o Poll - Polling 30 30 Milion Clients A All O Over the World Doesn't 't Scale o Custom Memory ry Allocator - Optimizing Memory ry is Hard

  12. print("Python" + " is " + "cool!") "Python is easy to use, powerful, and versatile, making it a great choice for beginners and experts alike." – codeschool.com

  13. print("Python" + " is " + "cool!") "Python is easy to use , powerful, and versatile, making it a great choice for beginners and experts alike." – codeschool.com

  14. print("Python" + " is " + "cool!") "Python is easy to use , powerful, and versatile, making it a great choice for beginners and experts alike." – codeschool.com public class Main { public static void main(String[] args) { System.out.println("Hello world!"); } }

  15. print("Python" + " is " + "cool!") "Python is easy to use , powerful, and versatile, making it a great choice for beginners and experts alike." – codeschool.com public class Main { print("Hello world!") public static void main(String[] args) { System.out.println("Hello world!"); } }

  16. print("Python" + " is " + "cool!") "Python is easy to use, powerful , and versatile, making it a great choice for beginners and experts alike." – codeschool.com

  17. print("Python" + " is " + "cool!") "Python is easy to use, powerful , and versatile, making it a great choice for beginners and experts alike." – codeschool.com Big names using Python

  18. print("Python" + " is " + "cool!") "Python is easy to use, powerful, and versatile , making it a great choice for beginners and experts alike." – codeschool.com https://opencv .org/ Image Processing using Python

  19. print("Python" + " is " + "cool!") "Python is easy to use, powerful, and versatile , making it a great choice for beginners and experts alike." – codeschool.com https://www.pygame.org Game Development using Python

  20. print("Python" + " is " + "cool!") "Python is easy to use, powerful, and versatile , making it a great choice for beginners and experts alike." – codeschool.com https://matplotlib.org/ Data Science using Python

  21. print("Python" + " is " + "cool!") "Python is easy to use, powerful, and versatile , making it a great choice for beginners and experts alike." – codeschool.com https://github.com/amueller/word_cloud Natural Language Processing (NLP) and T ext Mining using Python

  22. Python Setup o https://www.python.org/downloads/

  23. Python Setup o Pyt ython(x,y ,y) ) - https://pyt ython-xy.github.i .io/

  24. Python Command Line o Using command line o Python script in file o comment o Environment variables (Windows) o modules o import sys o sys.argv o dir(sys) o help(sys) o help(sys.exit)

  25. Variables and Data Types

  26. Variables and Data Types o Variables store and give names to data values o Data values can be of various types: o int -5, 0, 1000000 o float -2.0, 3.14159 o bool True, False o str "Hello world!", "K3WL" o list [1, 2, 3, 4], ["Hello", "world!"], [1, 2, "Hello"], [ ] o … o In Python, variables do not have types!

  27. Conditionals and Loops 27

  28. Conditionals and Loops

  29. Conditionals and Loops o Cores of programming! o Rely on boolean expressions which return either True or False o 1 < 2 : True o 1.5 >= 2.5 : Fals lse o answer == "Computer Science" : can be True or Fals lse depending on the value of variable answer o Boolean expressions can be combined with: and and, or or, not o 1 < 2 and 3 < 4 : True o 1.5 >= 2.5 or 2 == 2 : True o not 1.5 >= 2.5 : True

  30. Conditionals and Loops if boolean-expression-1: code-block-1 elif boolean-expression-2: code-block-2 (as many elif's as you want) else: code-block-last

  31. Conditionals and Loops grade = int(raw_input("Numeric grade: ")) if grade >= 80: print("A") elif grade >= 65: print("B") elif grade >= 55: print("C") else: print("E")

  32. Loops o Useful for repeating code! o Two variants:

  33. While Loops

  34. For Loops o So far, we have seen (briefly) two kinds of collections: string and list o For loops can be used to visit e each collection's 's element:

  35. Functions 35

  36. Functions • Functions encapsulate code blocks • Why functions? Modularization and reuse! • Y ou actually have seen examples of functions: • print() • raw_input() • Generic form: def function-name(parameters): code-block return value 36

  37. Functions: Celcius to Fahrenheit def function-name(parameters): code-block return value def celsius_to_fahrenheit(celsius): fahrenheit = celsius * 1.8 + 32.0 return fahrenheit

  38. Functions: Default and Named Parameters def hello(name_man="Bro", name_woman="Sis"): print("Hello, " + name_man + " & " + name_woman + "!") >>> hello() Hello, Bro & Sis! >>> hello(name_woman="Lady") Hello, Bro & Lady! >>> hello(name_woman="Mbakyu",name_man="Mas") Hello, Mas & Mbakyu! 38

  39. Imports • Code made by other people shall be reused! • Two ways of importing modules (= Python files): • Generic form: import module_name import math print(math.sqrt(4)) • Generic form: from module_name import function_name from math import sqrt print(sqrt(4))

  40. Strings 40

  41. String • String is a sequence of characters, like "Python is cool" • Each character has an index P y t h o n i s c o o l 0 1 2 3 4 5 6 7 8 9 10 11 12 13 • Accessing a character: string[index] x = "Python is cool" print(x[10]) • Accessing a substring via slicing: string[start:finish] print(x[2:6])

  42. String Operations P y t h o n i s c o o l 0 1 2 3 4 5 6 7 8 9 10 11 12 13 >>> x = "Python is cool" >>> "cool" in x # membership >>> len(x) # length of string x >>> x + "?" # concatenation >>> x.upper() # to upper case >>> x.replace("c", "k") # replace characters in a string >>> “ Hi %s ” % name # parameters in a string 42

  43. String Operations: Split P y t h o n i s c o o l 0 1 2 3 4 5 6 7 8 9 10 11 12 13 x.split(" ") P y t h o n i s c o o l 0 1 2 3 4 5 0 1 0 1 2 3 >>> x = "Python is cool" >>> x.split(" ") 43

  44. String Operations: Join P y t h o n i s c o o l 0 1 2 3 4 5 0 1 0 1 2 3 ",".join(y) P y t h o n , i s , c o o l 0 1 2 3 4 5 6 7 8 9 10 11 12 13 >>> x = "Python is cool" >>> y = x.split(" ") >>> ",".join(y) 40

  45. Input/Output 45

  46. Input/Output • Working with data heavily involves reading and writing! • Data come in two types: • T ext: Human readable, encoded in ASCII/UTF-8, example: .txt, .csv • Binary: Machine readable, application-specific encoding, example: .mp3, .mp4, .jpg 46

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend