Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS...
-
Upload
madeline-morrison -
Category
Documents
-
view
242 -
download
5
Transcript of Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS...
![Page 1: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/1.jpg)
Introduction to Python
SPARCS `08 서우석 (pipoket)
`09 Summer SPARCS Seminar
![Page 2: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/2.jpg)
▶ Python?
Father Guido Van
Rossum
Birth-year 1989
Born at Amsterdam
![Page 3: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/3.jpg)
▶ Python?
Platform independent
Interpreter Language
Script Language
Supports OOPObject Oriented Program-
ming
![Page 4: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/4.jpg)
▶ Why Python
Easy Syntax Easy Grammar Easy Data Structure Many Packages
Very Readable Very Flexible Usually Short
Code
Easy to Manage CodeEasy to Work Together
![Page 5: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/5.jpg)
▶ Python!
SPARCS Works Together with…
![Page 6: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/6.jpg)
▶ Get Python!
http://www.python.org
DOWNLOAD
Recommended Version 2.6.X <=
On Windows
![Page 7: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/7.jpg)
▶ Get Python!
On Debian Linux
~# apt-get install python
~$ sudo apt-get install python
![Page 8: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/8.jpg)
▶ Run Python!
~$ python
![Page 9: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/9.jpg)
▶ Run Python!
~# apt-get install ipython ~# ipython
![Page 10: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/10.jpg)
▶ Python Syntax
Use python as simple calculator
>>> 1 + 2>>> 6 * 8>>> 6.0 * 8>>> 2 ^ 10>>> 2 ** 10>>> _ / 2>>> __ / 4>>> _
![Page 11: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/11.jpg)
▶ Python Syntax
Print the “Hello world!”
>>> print “Hello World!”
>>> print(“Hello World!”)
![Page 12: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/12.jpg)
▶ Python SyntaxMultiline Text
Single Quote
INDENTATION!!
![Page 13: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/13.jpg)
▶ Python Syntax
Indentation is also Syntax!!!
![Page 14: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/14.jpg)
▶ Python Syntax
You MUST keep the same indenta-
tion!
![Page 15: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/15.jpg)
▶ Python Variables
Type Example
Number (integer, long, float …) 3, 3.141592, 31415928808L
String, Unicode “English”, u”한글” , u”Español”
Tuple (‘First’, ‘Second’, ‘Third’)
List [‘First’, ‘Second’, ‘Third’]
Dictionary {‘First’: 1, ‘Second’: 2, ‘Third’: 3}
But you don’t have to care!
![Page 16: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/16.jpg)
▶ Python Variables
Dynamic Typing
![Page 17: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/17.jpg)
▶ Do It Yourself #1
Your program should do the following1. Calculate the 224
2. Save the result to “result”3. Print the “result”
![Page 18: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/18.jpg)
▶ Python Controls
if
for
while
try, except
![Page 19: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/19.jpg)
▶ if
“a is three”
![Page 20: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/20.jpg)
▶ for
![Page 21: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/21.jpg)
▶ while
![Page 22: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/22.jpg)
▶ try, except
![Page 23: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/23.jpg)
▶ Do It Yourself #2
Your program should do the following1. Print out the even numbers between 1 to 1000, without line breaks2. Print out the 1000 / n When n is between -100 to 100
![Page 24: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/24.jpg)
▶ Number
7
0
7.0
0.75
5+5j
![Page 25: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/25.jpg)
▶ String
![Page 26: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/26.jpg)
▶ String
![Page 27: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/27.jpg)
▶ Do It Yourself #3
Your program should do the following1. Let given=“we are so friend!”2. Using slicing, concatenating, in-dexing, and methods, make following result
- “we are friend!”- “are WE so friend”- “so friend we are”
![Page 28: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/28.jpg)
▶ List, Tuple
![Page 29: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/29.jpg)
▶ List, Tuple
![Page 30: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/30.jpg)
▶ Do It Yourself #4
Your program should do the following1. Let given=range(100)2. Using the given, get the following
- Even number between 0~99- Odd number between 0~99- Multiplier of 3 between 0~50,
70~99- List starts from 99 and ends at 1
![Page 31: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/31.jpg)
▶ Dictionary
![Page 32: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/32.jpg)
▶ Dictionary
![Page 33: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/33.jpg)
▶ Dictionary
![Page 34: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/34.jpg)
▶ Simple input
![Page 35: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/35.jpg)
▶ Do It Yourself #5
Your program should do the following1. Get the input Name and Age2. Save the Name and Age to dictio-nary3. If input is empty Change the input mode to search4. On search mode Print the age of given name
![Page 36: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/36.jpg)
▶ File Operation
![Page 37: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/37.jpg)
▶ Summary
Now you know…How to Install and Run PythonHow to Use Python as CalculatorBasic Python Syntax
(indentation, quote, multiline text…)
Python Data Structure (string, number, list, dictionary, tuple…)
Basic Input, Output to the terminal(input_raw, input, print)
Basic File Operation(open, write, readline, close …)
![Page 38: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/38.jpg)
▶ Summary
You have just learned 50% of python!
![Page 39: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/39.jpg)
▶ Next
FunctionClass with OOP
(Inheritance, Overloading, Overriding …)
PackageAdvanced Python Topics
Simple Format StringList GeneratingGenerator (yield)
Lambda Function (lambda)
![Page 40: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/40.jpg)
▶ Homework
• You should review all the materials we have discussed
• You can get the codes used in this ppthttp://pipoket.kaist.ac.kr/sp_seminar/week01.tar.gz
• Following command will expand the file on Linux ~# tar –zxvf week01.tar.gz
![Page 41: Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.](https://reader035.fdocuments.net/reader035/viewer/2022062309/56649e805503460f94b847d5/html5/thumbnails/41.jpg)
▶ HomeworkYour program should do the following
1. Open the given file diy6.db2. File is like this
“20080421[TAB]Woosuk Suh[TAB]Computer Science”
“20080719TAB]Chanhee Lee[TAB]Undecided”
3. Read the file and save the data as you wish4. Get the Student ID as input and print out the information of student