Python Tutorial

Python Tutorial

Mickey Nguyen

Python Tutorial

Written by:

Mickey Nguyen

(linkedin: mickeytrong73@)

2015

1

Python Tutorial

Mickey Nguyen

1

Python Installation ................................................................................................................................ 4

2

Introduction ........................................................................................................................................ 13

3

Print ..................................................................................................................................................... 22

4

String ................................................................................................................................................... 25

5

Read input then print it out ................................................................................................................ 27

6

While loop ........................................................................................................................................... 28

7

For loop ............................................................................................................................................... 30

8

Function .............................................................................................................................................. 32

9

Overloading function .......................................................................................................................... 34

10 if-elif-else ............................................................................................................................................ 36

11 Switch-case ......................................................................................................................................... 37

12 Enum ................................................................................................................................................... 37

13 Array .................................................................................................................................................... 39

14 List-Tuple-Dictionary ........................................................................................................................... 40

15 Queue.................................................................................................................................................. 43

16 Modules .............................................................................................................................................. 44

17 Use local time and calendar ................................................................................................................ 47

18 Bitwise ................................................................................................................................................. 48

19 FileIO ................................................................................................................................................... 50

20 Class .................................................................................................................................................... 51

21 Inheritant ............................................................................................................................................ 53

21.1

Child and Parent on same file ..................................................................................................... 53

21.2

Parent and Child on separate files .............................................................................................. 55

22 Abstract class ...................................................................................................................................... 57

23 Thread ................................................................................................................................................. 60

24 Networking Socket .............................................................................................................................. 62

24.1

UDP client-server ........................................................................................................................ 62

24.2

TCP client-server ......................................................................................................................... 64

25 Exception Handling ............................................................................................................................. 66

26 Run Java Code ..................................................................................................................................... 70

26.1

Calling Java JAR runnable ............................................................................................................ 70

26.2

Calling Java method .................................................................................................................... 71

2

Python Tutorial

Mickey Nguyen

27 Regular Expression (Regex) ................................................................................................................. 73

Regular Expression Modifiers: Option Flags ................................................................................................. 73

Regular Expression Patterns....................................................................................................................... 74

27.1

Match .......................................................................................................................................... 76

27.2

Search.......................................................................................................................................... 78

27.3

re.match vs re.search .................................................................................................................. 80

27.4

Search and Replace ..................................................................................................................... 80

27.5

find() sub-string, re.findall (regex), re.finditer (index of all matched) ....................................... 81

27.6

Spliting the string ........................................................................................................................ 83

28 Some useful examples of Python script .............................................................................................. 84

28.1

Directory exist? Or created it ...................................................................................................... 84

28.2

File exist? Or Create it ................................................................................................................. 86

28.3

Copy,move file between folders(directories) ............................................................................. 87

28.4

Run Java (JAR) and using Jython to acces Java code................................................................... 87

28.4.1

Calling Java JAR runnable .................................................................................................... 88

28.4.2

Calling Java method ............................................................................................................ 88

29 XML Processing ................................................................................................................................... 88

30 CGI (Common Getway Interface) programming ................................................................................. 90

31 Database Access.................................................................................................................................. 90

32 GUI Programming................................................................................................................................ 90

3

Python Tutorial

Mickey Nguyen

1 Python Installation

I am going to use Eclipse as IDE (Integrated development environment) compiler. Download Eclipse at



ipse-jee-luna-R-win32-x86_64.zip

Save Eclipse zip file in your local, then extract all. After extract all, it looks like this

To launch Eclipse simply just double click on eclipse. Before do this, create a folder in your local drive

name it as ¡°Myworkspace¡±, you can name it whatever you want. It will be a director contain all of your

work.

4

Python Tutorial

Mickey Nguyen

You can close the Welcome screen

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download