Download presentation
Presentation is loading. Please wait.
Published byMadeline Morrison Modified over 9 years ago
1
Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar
2
▶Python? Father Guido Van Rossum Birth-year 1989 Born at Amsterdam
3
▶Python? Platform independent Interpreter Language Script Language Supports OOP Object Oriented Programming
4
▶ Why PythonWhy Python Easy Syntax Easy Grammar Easy Data Structure Many Packages Easy Syntax Easy Grammar Easy Data Structure Many Packages Very Readable Very Flexible Usually Short Code Very Readable Very Flexible Usually Short Code Easy to Manage Code Easy to Work Together Easy to Manage Code Easy to Work Together
5
▶Python! SPARCS Works Together with…
6
▶ Get Python!Get Python! http://www.python.org DOWNLOAD Recommended Version 2.6.X <= On Windows
7
▶ Get Python!Get Python! On Debian Linux ~# apt-get install python ~$ sudo apt-get install python
8
▶ Run Python!Run Python! ~$ python
9
▶ Run Python!Run Python! ~# apt-get install ipython ~# ipython ~# apt-get install ipython ~# ipython
10
▶ Python SyntaxPython Syntax Use python as simple calculator >>> 1 + 2 >>> 6 * 8 >>> 6.0 * 8 >>> 2 ^ 10 >>> 2 ** 10 >>> _ / 2 >>> __ / 4 >>> _ >>> 1 + 2 >>> 6 * 8 >>> 6.0 * 8 >>> 2 ^ 10 >>> 2 ** 10 >>> _ / 2 >>> __ / 4 >>> _
11
▶ Python SyntaxPython Syntax Print the “Hello world!” >>> print “Hello World!” >>> print(“Hello World!”)
12
▶ Python SyntaxPython Syntax Multiline Text Single Quote INDENTATION!!
13
▶ Python SyntaxPython Syntax Indentation is also Syntax!!!
14
▶ Python SyntaxPython Syntax You MUST keep the same indentation!
15
▶ Python VariablesPython Variables TypeExample 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!
16
▶ Python VariablesPython Variables Dynamic Typing
17
▶ Do It Yourself #1Do It Yourself #1 Your program should do the following 1. Calculate the 2 24 2. Save the result to “result” 3. Print the “result”
18
▶ Python ControlsPython Controls if for while try, except
19
▶if “a is three”
20
▶for
21
▶while
22
▶ try, excepttry, except
23
▶ Do It Yourself #2Do It Yourself #2 Your program should do the following 1. Print out the even numbers between 1 to 1000, without line breaks 2. Print out the 1000 / n When n is between -100 to 100
24
▶Number 7 7 0 0 7.0 0.75 5+5j
25
▶String
26
▶String
27
▶ Do It Yourself #3Do It Yourself #3 Your program should do the following 1. Let given=“we are so friend!” 2. Using slicing, concatenating, indexing, and methods, make following result - “we are friend!” - “are WE so friend” - “so friend we are”
28
▶ List, TupleList, Tuple
29
▶
30
▶ Do It Yourself #4Do It Yourself #4 Your program should do the following 1. 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
31
▶Dictionary
32
▶Dictionary
33
▶Dictionary
34
▶ Simple inputSimple input
35
▶ Do It Yourself #5Do It Yourself #5 Your program should do the following 1. Get the input Name and Age 2. Save the Name and Age to dictionary 3. If input is empty Change the input mode to search 4. On search mode Print the age of given name
36
▶ File OperationFile Operation
37
▶Summary Now you know… How to Install and Run Python How to Use Python as Calculator Basic 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 …)
38
▶Summary You have just learned 50% of python!
39
▶Next Function Class with OOP (Inheritance, Overloading, Overriding …) Package Advanced Python Topics Simple Format String List Generating Generator (yield) Lambda Function (lambda)
40
▶Homework You should review all the materials we have discussed http://pipoket.kaist.ac.kr/sp_seminar/week01.tar.gz http://pipoket.kaist.ac.kr/sp_seminar/week01.tar.gzYou can get the codes used in this ppt http://pipoket.kaist.ac.kr/sp_seminar/week01.tar.gz http://pipoket.kaist.ac.kr/sp_seminar/week01.tar.gz Following command will expand the file on Linux ~# tar –zxvf week01.tar.gz
41
▶Homework Your program should do the following 1. Open the given file diy6.db 2. 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 wish 4. Get the Student ID as input and print out the information of student
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.