Swaroop, C. H.
??:
:shiiuen
1
?
3\WKRQ
1.
??
··········································
2
1.1
····················3
1.2
·······································3
1.2.1
···········································3
1.2.2
····························4
1.3
Python
·························4
1.4
···········································5
2.
··································
5
2.1
····························6
2.2
······················································6
2.3
···············································6
2.4
···················································7
2.5
····································7
2.6
···········································8
2.7
···················································8
2.8
???????
································9
2.9
??
················································· 11
3.
····················
11
3.1
??
················································· 11
3.2
???
············································· 11
3.3
·································· 13
3.3.1
·································· 14
3.3.2
·································· 14
3.4
············································· 14
4.
····································
15
4.1
??
················································· 15
4.2
if
·············································· 15
4.2.1
??
if
······························· 15
4.2.2
······························ 16
4.3
while
········································ 17
4.3.1
??
while
························· 17
4.3.2
······························ 18
4.4
for
············································ 18
4.4.1
??
for
····························· 18
4.4.2
······························ 19
4.5
break
········································ 19
4.5.1
??
break
························· 19
4.5.2
·····························
20
4.6
continue
···································
20
4.6.1
??
continue
····················
20
4.6.2
·····························
21
5.
·······································
21
5.1
??
················································
21
5.1.1
·································
21
5.1.2
·····························
22
5.2
·········································
22
5.2.1
··························
22
5.2.2
·····························
23
5.3
·········································
23
5.3.1
··························
23
5.3.2
·····························
23
5.3.3
??
global
························
24
5.4
·····································
24
5.4.1
······················
25
5.4.2
·····························
25
5.5
·········································
25
5.5.1
··························
26
5.5.2
·····························
26
5.6
return
·······································
26
5.6.1
··········
26
5.6.2
·····························
27
5.7
DocStrings ·······································
27
5.7.1
??
DocStrings ························
27
5.7.2
·····························
28
6.
·······································
28
6.1
??
················································
28
6.1.1
??
sys
····························
29
6.2
.pyc
·······················
30
6.3
from..import
·····························
30
6.4
__name__ ·····························
30
6.4.1
__name__ ··············
30
6.5
··························
31
6.5.1
··················
31
6.5.2
from..import ·····························
32
6.6
dir()
··········································
32
6.6.1
??
dir
·····························
32
Swaroop, C. H.
??:
:shiiuen
2
7.
································
34
7.1
??
················································· 34
7.2
················································· 34
7.2.1
··············· 34
7.2.2
·································· 34
7.3
················································· 36
7.3.1
·································· 36
7.3.2
······················ 37
7.4
················································· 38
7.4.1
·································· 38
7.5
················································· 40
7.5.1
·································· 40
7.6
················································· 42
7.6.1
······························ 42
7.7
·························· 43
7.7.1
·························· 43
8.
??
Python
·····················
44
8.1
? 乬
················································· 44
8.2
········································· 45
8.2.1
····································· 45
8.2.2
····································· 47
8.2.3
····································· 49
8.2.4
····································· 50
8.2.5
······························ 52
8.3
·································· 53
9.
····················
53
9.1
??
················································· 53
9.2
self ··················································· 54
9.3
?
···················································· 54
9.3.1
······························ 54
9.4
····································· 55
9.4.1
······················ 55
9.5
__init__
···································· 55
9.5.1
??
__init__
····················· 55
9.6
······························ 56
9.6.1
··············· 57
9.7
················································· 59
9.7.1
·································
60
10.
/
·······························
62
10.1
················································
62
10.1.1
·································
62
10.2
·············································
63
10.2.1
··························
63
11.
·······································
64
11.1
??
················································
65
11.2
try..except
········································
65
11.2.1
·································
65
11.3
·········································
66
11.3.1
··························
66
11.4
try..finally
········································
68
11.4.1
??
finally ·······························
68
12.
Python
·························
69
12.1
??
················································
69
12.2
sys
············································
69
12.2.1
·····························
69
12.2.2
sys
·························
71
12.3
os
·············································
71
13.
Python
·················
72
13.1
·····································
72
13.2
·········································
72
13.3
·········································
73
13.3.1
··························
73
13.4
··············
73
13.5
lambda
·····································
74
13.5.1
·····························
74
13.6
exec
eval
·······························
75
13.7
assert
········································
75
13.8
repr
··········································
75
14.
················
75
14.1
·········································
76
14.1.1
GUI
··························
77
1.
?
?
Python
ā
Hello World
ā
Python
Swaroop, C. H.
??:
:shiiuen
3
Python
1.1
?
shell
python
print 'Hello World'
Enter
Hello World
?
Windows
PA
TH
IDLE
IDLE
->
->Python 2.3->IDLE(Python GUI)
?
Linux
IDLE
?
>>>
Python
?
1.1
Python
KHOORZRUOG
!!!Python
Python
print
Hello World
Python
Linux/BSD shell
Ctrl-d
Windows
Ctrl-z
Enter
?
1.2
Hello World
ā
Hello World
ā
Hello World
ā??
Hello World
Simon Cozens[1]
ā
helloworld.py
?
?
1.2
SULQW+HOOR:RUOG
shell
?
Linux
DOS
python helloworld.py
?
IDLE
Edit->Run Script
Ctrl-F5
1.2.1
+HOOR:RUOG
Swaroop, C. H.
??:
:shiiuen
4
Python
Python
??
print
?
Print
p
P
?
1.2.2
??
#
Python
???
#!
Linux/Unix
python
helloworld.py
???
Python
ā
Hello World
ā?
print
?ā
Hello World
ā
1.3
Python
Linux/Unix
??
Windows
chmod
??
+HOOR:RUOG
chmod
./
helloworld
?
./helloworld
?
???
PA
TH
PATH
PA
TH
Q
Swaroop, C. H.
??:
:shiiuen
5
+HOOR:RUOG
echo
PATH
$
shell
/home/swaroop/bin
PA
TH
swaroop
?
?
?
?
?
?
?
г
?
?
?
?
?
?
PATH
?
Ё
ü
ü
?
?
?
?
?
?
PATH=$PATH:/home/swaroop/mydir
/home/swaroop/mydir
PA
TH
cd
Linux
DOS
1.4
?
Python
help
help(str)
str
str
T
Python
help()
help
print
PYTHONDOCS
Linux/Unix
env
3\WKRQ2FW
print
Python
print
Fedora Core 3 Linux
2.
Hello World
Python
Swaroop, C. H.
??:
:shiiuen
6
2.1
5
?
1.23
?
9.25e-3
'This is a string'
?
"It's a string!"
2
2.2
Python
4
z
2
zz
3.23
52.3E-4
E
10
52.3E-4
??
52.3 * 10-4
?
z
(-5+4j)
(2.3-4.6j)
2.3
Python
Python
z
'
?
'Quote me on this'
z
"
?
"What's your name?"
?
z
'''
"""
?
z
? Н?
'
?
What's your
name?
'What's your name?'
Python? Н?
\'
'What\'s your name?'
?"What's your name?"
Swaroop, C. H.
??:
:shiiuen
7
ㄝ ??
"This is the first sentence. This is the second sentence."
z
r
R
r"Newlines are indicated by \n"
?
z
Unicode
UnicodeUnicode
Python
Unicode
u
U
?
u"This
is a Unicode string."
?
Unicode
zz
Python
'What\'s' 'your name?'
"What's your name?"
?
U??
2.4
?
2.5
z
t
_
???
Swaroop, C. H.
??:
:shiiuen
8
z
t
_
?
0-9
z
myname
myName
n
N
?
z
i
?
__my_name
?
name_23
a1b2_c3
?
z
2things
?
this is spaced out
my-name
?
2.62.7
???
Python
??
ā
ā?
3\WKRQ
3\WKRQ
3\WKRQ
3\WKRQ
,'/(
?
2.1
L
L L
Swaroop, C. H.
??:
:shiiuen
9
=
5
i
????
i
5
print
?
i
i
1
i
6
?
s
?
&&????
2.8
?
??????
??
??
Python
??
Python
???
??
?
?
print 'Hello World'
Python
;
???/
L
Swaroop, C. H.
??:
:shiiuen
10
L
L SULQWLL SULQWL?
Python
?
7KLVFRQWLQXHVWKHVWULQJ
L
Swaroop, C. H.
??:
:shiiuen
11
2.9
?
?Python
?
?
?
乏
L
Python
3.3.1
??
2 + 3
3.2
???
Swaroop, C. H.
??:
:shiiuen
12
2 + 3
Python
!!!!!!
!!!
?
3.1
???
[
?
[
??
\
?
!!_Aa
a
[
\???????
7UXH
)DOVH
)DOVH??
7UXH?
?
7UXH?
!
[
\
!
7UXH?????
)DOVH?
[
\
7UXH?
Swaroop, C. H.
??:
:shiiuen
13
!
[
\
7UXH?
[
\
[
7UXH?[
\
[
7UXH?
7UXH?
QRW
[
?
7UXH??
)DOVH?[
?
)DOVH??
7UXH?
)DOVH?
DQG
[
?
)DOVH?
[
)DOVH??
)DOVH????3\WKRQ
????
\?????????
)DOVH??[
)DOVH????
RU
[
7UXH??
7UXH?
7UXH?
3.3
?
2 + 3 * 4Python
??
Python
Python
2 + (3 * 4)
2 + 3 * 4
2 + (3 + 4)
??
?
3.2
Swaroop, C. H.
??:
:shiiuen
14
+
-
3.3.1
?
(2 + 3) * 4
3.3.2
2 + 3 + 4
(2 + 3) + 4
a = b = c
a = (b = c)
?
3.4
?
3.1
EUHDGWK
SULQW$UHDLVDUHD
SULQW3HULPHWHULVOHQJWKEUHDGWK
3HULPHWHULV
length * breadth
area
Ё
??
print
2 * (length +
breadth)
Python
'Area is'
area
Python
ぎ ?? 乬?
Python
???
/DPEGD
RUDQG
QRW[
LQ?QRWLQLV?LVQRW
_A
Ь ?????
a[
[DWWULEXWH
[>LQGH[@
[>LQGH[LQGH[@IDUJXPHQWV^NH\GDWXP`
Swaroop, C. H.
??:
:shiiuen
15
4.4.1
??
Python
?
Python
if
?
for
while
?
4.2
if
if
if-
??
???
else-
??
else
4.2.1
??
if
?
4.1
??
if
LIJXHVV QXPEHUHOLIJXHVVQXPEHU
HOVH
SULQW'RQH
H[HFXWHG
DIWHU
WKHLIVWDWHPHQWLV
H[HFXWHG
(QWHUDQLQWHJHU
'RQH
Swaroop, C. H.
??:
:shiiuen
16
(QWHUDQLQWHJHU
'RQH
(QWHUDQLQWHJHU
&RQJUDWXODWLRQV\RXJXHVVHGLW
'RQH
4.2.2
number
??
23
raw_input()
raw_input
raw_input
int
guess
Ё?
int
?
Python
Python
if
Python
elif
if else-if else
if-elif-else
elif
else
?
if
if
if
???
elif
else
if
Python
if
elif
else
ifprint 'Done'
Python
Swaroop, C. H.
??:
:shiiuen
17
C/C++
ā ?? ā?
?
&&????
3\WKRQ
VZLWFK
4.3
while
?
while
while
while
else
4.3.1
??
while
?
3.2
??
while
HOVH
SULQW'RQH
(QWHUDQLQWHJHU
Swaroop, C. H.
??:
:shiiuen
18
(QWHUDQLQWHJHU(QWHUDQLQWHJHU
&RQJUDWXODWLRQV\RXJXHVVHGLW
'RQH
4.3.2
while
???
raw_input
if
while
while
running
True
running
True
while-
running
while-
else-
while
False
else
while
else
while
True
False
1
0
1
?
else
while
while
?
&&????ZKLOH
HOVH
4.4
for
for..in4.4.1
??
for
?
3.3
??
for
Swaroop, C. H.
??:
:shiiuen
19
HOVH
4.4.2
range
range
range(1,5)
[1, 2, 3, 4]
range
????
1
range
range(1,5,2)
[1,3]
????
range
for
for i in range(1,5)
ㄝ ??
for i in [1, 2, 3, 4]
i
i
i
???
else
else
for
break
???
for..in
range
?
3\WKRQ
?
IRU
&&?
IRU
3\WKRQ
?
IRU
& Ё?
IRUHDFK
-DYD
Ё?
&& Ё ???
3\WKRQ??
IRU
L
LQ
UDQJH?????3\WKRQ
?
IRU
4.5
break
break
??
False
for
while
??
else
4.5.1
??
break
?
3.4
??
break
Swaroop, C. H.
??:
:shiiuen
20
ZKLOH7UXH
SULQW'RQH
'RQH
4.5.2
'quit'
???
??
len
???
break
for
4.6
continue
continue
Python
??
4.6.1
??
continue
?
3.5
??
continue
Swaroop, C. H.
??:
:shiiuen
21
ZKLOH7UXH
(QWHUVRPHWKLQJD(QWHUVRPHWKLQJ(QWHUVRPHWKLQJDEF
,QSXWLVRIVXIILFLHQWOHQJWK
4.6.2
3
len
3
continue
continue
for
5.5.1
??
??
len
range
?
def
def
5.1.1
?
5.1
Swaroop, C. H.
??:
:shiiuen
22
+HOOR:RUOG
5.1.2
sayHello
5.2
?
5.2.1
?
5.2
SULQW0D[GLUHFWO\JLYHOLWHUDOYDOXHV
[ \
Swaroop, C. H.
??:
:shiiuen
23
5.2.2???
printMax
a
b
?
if..else
printMax
printMax(x, y)
x
a
y
b
printMax
5.3
??
?
5.3.1
?
5.3
GHIIXQF[
[ IXQF[[LV
[LVVWLOO
5.3.2
x
?
Python
2
??
x
?
x
x
x
Swaroop, C. H.
??:
:shiiuen
24
print
x
5.3.3
?
?
global
Python
??
global
global
??
global
?
5.4
??
global
GHIIXQF
[ IXQF[LV
&KDQJHGJOREDO[WR
9DOXHRI[LV
5.3.3.1
global
x
x
Ё ??
x
global
global x, y, z
?
5.4
??
=
Swaroop, C. H.
??:
:shiiuen
25
5.4.1
?
?
5.5
GHIVD\PHVVDJHWLPHV
VD\+HOOR
VD\:RUOG
+HOOR
:RUOG:RUOG:RUOG:RUOG:RUOG
5.4.2
say
times
1
say
say
5
?
5
??
IXQFD
E ???
GHIIXQFD E??
5.5
?
Swaroop, C. H.
??:
:shiiuen
26
5.5.1
?
?
5.6
IXQF
5.5.2
func
func(3, 7)
a
3
b
7
c
10
?
func(25, c=24)
a
25
c
24
b
5
?
func(c=50, a=100)
a
c
a
c
5.6
return
return
?
5.6.1
?
5.7
GHIPD[LPXP[\
Swaroop, C. H.
??:
:shiiuen
27
5.6.2
maximum
if..else
return
return None
?
None
Python
None
return
return None
print someFunction()
??
someFunction
return
GHIVRPH)XQFWLRQ
pass
Python
5.7
DocStrings
Python
docstrings
?
DocStrings
???5.7.1
??
DocStrings
?
5.8
??
DocStrings
Swaroop, C. H.
??:
:shiiuen
28
SULQW0D[
SULQWSULQW0D[BBGRFBB
5.7.2
DocStrings
__doc__
printMax
????
Python
?????
Python
Ё ???
help()
?
DocStings
?????
__doc__
help(printMax)
???
q
help
?
Python
pydoc
help()
DocStrings
?
6.6.1
??
.py
Swaroop, C. H.
??:
:shiiuen
29
Python
6.1.1
?
?
sys
?
6.1
??
sys
SULQW7KHFRPPDQGOLQHDUJXPHQWVDUH
7KHFRPPDQGOLQHDUJXPHQWVDUH
XVLQJBV\VS\
ZHDUH
DUJXPHQWV
6.1.1.1
import
sys
Python
sys
Python
Python
import sys
sys.path
sys.py
??
?
???
ā
sys
system
Swaroop, C. H.
??:
:shiiuen
30
sys
argv
sys.argv
argv
sys
sys.argv
sys.argv
?
IDE
???
python using_sys.py we are arguments
python
using_sys.py
Python
sys.argv
???
sys.argv
'using_sys.py'
sys.argv[0]
?
'we'
sys.argv[1]
?
'are'
sys.argv[2]
'arguments'
sys.argv[3]
Python
?
0
1
sys.path
sys.path
sys.path
PYTHONPA
TH
sys.path
6.2
????
.pyc
Python
.pyc
Python
Python
.pyc
.pyc
6.3
from..importargv
sys.
??
from sys import argv
sys
from sys import *
from..import
???
import
6.4
__name__
??
__name__
6.4.1
__name__
?
6.2
__name__
Swaroop, C. H.
??:
:shiiuen
31
HOVH
!!!LPSRUWXVLQJBQDPH
,DPEHLQJLPSRUWHGIURPDQRWKHUPRGXOH
!!!
6.4.1.1
??
Python
__name__
'__main__'
6.5
Python
.py
6.5.1
?
6.3
GHIVD\KL
YHUVLRQ
Python
Python
sys.path
Swaroop, C. H.
??:
:shiiuen
32
P\PRGXOHVD\KL
9HUVLRQ
6.5.1.1
Python
Python
6.5.2
from..import
from..import
IURPP\PRGXOHLPSRUWVD\KLYHUVLRQ
mymodule_demo2.py
mymodule_demo.py
6.6
dir()
dir
dir()
6.6.1
??
dir
?
6.4
??
dir
!!!LPSRUWV\V
Swaroop, C. H.
??:
:shiiuen
33
>BBEXLOWLQVBBBBGRFBBBBQDPHBBV\V@
!!!
>BBEXLOWLQVBBBBGRFBBBBQDPHBBDV\V@
!!!!!!
>BBEXLOWLQVBBBBGRFBBBBQDPHBBV\V@
!!!
6.6.1.1
sys
dir
dir
dir
a
dir
del
/
dir
del
/
del
a
a
Swaroop, C. H.
??:
:shiiuen
34
7.7.1
??
?
Python
7.2list
Python
Python
7.2.1
i
5
int
i
help(int)
Python
?
list
append
mylist.append('an item')
mylist/
mylist.field
?
7.2.2
?
7.1
VKRSOLVW >DSSOHPDQJRFDUURWEDQDQD@
Swaroop, C. H.
??:
:shiiuen
35
IRULWHPLQVKRSOLVW
SULQW0\VKRSSLQJOLVWLVQRZVKRSOLVWSULQW6RUWHGVKRSSLQJOLVWLVVKRSOLVWSULQW0\VKRSSLQJOLVWLVQRZVKRSOLVW
,DOVRKDYHWREX\ULFH
,ERXJKWWKHDSSOH
7.2.2.1
shoplist
shoplist
for..inprint
print
Swaroop, C. H.
??:
:shiiuen
36
append
print
sort
?
del
del
del shoplist[0]
????
Python
?
0
?
help(list)
7.3
?
7.3.1
?
7.2
]RR ZROIHOHSKDQWSHQJXLQQHZB]RR PRQNH\GROSKLQ]RR
SULQW$OODQLPDOVLQQHZ]RRDUHQHZB]RR
$OO
DQLPDOV
LQ
QHZ
]RR
DUH
Swaroop, C. H.
??:
:shiiuen
37
7.3.1.1zoo
len
new_zoo
???
?
????
new_zoo[2]
new_zoo
Ё ???? 乍 ??
new_zoo[2][2]
new_zoo
0
1
myempty = ()Python
2
singleton = (2 , )
?
?
3HUO
3HUO
3\WKRQ??
7.3.2
?
7.3
DJH
Swaroop, C. H.
??:
:shiiuen
38
7.3.2.1
print
%
%s
%d
%s
?
name
?
%d
?
age
?
Python
%s
name
print
%s
Python
print
%
7.4
d = {key1 : value1, key2 : value2 }
/
/
dict
/
7.4.1
?
7.4
DE ^6ZDURRSVZDURRSFK#E\WHRIS\WKRQLQIR
Swaroop, C. H.
??:
:shiiuen
39
DE>*XLGR@ JXLGR#S\WKRQRUJ
LI*XLGRLQDE25DEKDVBNH\*XLGR
6ZDURRSVDGGUHVVLVVZDURRSFK#E\WHRIS\WKRQLQIR
&RQWDFW6ZDURRSDWVZDURRSFK#E\WHRIS\WKRQLQIR
7.4.1.1
ab
???????/
Swaroop, C. H.
??:
:shiiuen
40
/
Guido
del
/
del
items
/
for..in
name
address
for
in
/
dict
??
has_key
help(dict)
dict
/
??
7.57.5.1
?
7.5
VKRSOLVW >DSSOHPDQJRFDUURWEDQDQD@
SULQW,WHPLVVKRSOLVW>@SULQW,WHPLVVKRSOLVW>@SULQW,WHPLVVKRSOLVW>@SULQW,WHPLVVKRSOLVW>@
SULQW,WHPLVVKRSOLVW>@SULQW,WHPLVVKRSOLVW>@
SULQW,WHPWRLVVKRSOLVW>@SULQW,WHPWRHQGLVVKRSOLVW>@SULQW,WHPWRLVVKRSOLVW>@
Swaroop, C. H.
??:
:shiiuen
41
SULQWFKDUDFWHUVWRHQGLVQDPH>@
SULQWFKDUDFWHUVVWDUWWRHQGLVQDPH>@
,WHPVWDUWWRHQGLV>DSSOHPDQJRFDUURWEDQDQD@
FKDUDFWHUVVWDUWWRHQGLVVZDURRS
7.5.1.1
Python
???
Python
?
0
shoplist[0]
shoplist[3]
shoplist
shoplist[-1]
??
shoplist[-2]
Python
Python
Swaroop, C. H.
??:
:shiiuen
42
?
???
shoplist[1:3]
1
2
3
shoplist[:]
shoplist[:-1]
??
Python
7.6
?
7.6.1
?
7.6
SULQW6LPSOH$VVLJQPHQW
VKRSOLVW >DSSOHPDQJRFDUURWEDQDQD@
SULQWVKRSOLVWLVVKRSOLVWSULQWVKRSOLVWLVVKRSOLVW
Swaroop, C. H.
??:
:shiiuen
43
VKRSOLVWLV>PDQJRFDUURWEDQDQD@
P\OLVWLV>PDQJRFDUURWEDQDQD@
VKRSOLVWLV>PDQJRFDUURWEDQDQD@
P\OLVWLV>FDUURWEDQDQD@
7.6.1.1
?
?
3HUO
7.7
str
help(str)
?
7.7.1
?
7.7
Swaroop, C. H.
??:
:shiiuen
44
LIDLQQDPH
P\OLVW >%UD]LO5XVVLD,QGLD&KLQD@
DSSOHPDQJRFDUURW@
GHOVKRSOLVWUHPRYHWKHVKRSOLVW
SULQWVWRUHGOLVW
10.2.1.1
import..as
cPickle
pickle
?
p
?
file
dump
?
pickle
load
?
11.
Python
Swaroop, C. H.
??:
:shiiuen
65
11.1
?
?
print
print
Print
Python
?
???????
+HOOR:RUOG
SyntaxError
11.2
try..except
Ctrl-d
!!!V UDZBLQSXW(QWHUVRPHWKLQJ!
(2)(UURU
Python
EOFError
????
??
Ctrl-d
???
11.2.1
try..except
try-
except-
?
11.1
WU\
Swaroop, C. H.
??:
:shiiuen
66
SULQW'RQH
(QWHUVRPHWKLQJ!
'RQH
11.2.1.1
try
except
/
except
/
?
try
except
Python
try..catch
else
else
11.3
raise
/
Error
Exception
11.3.1
?
11.2
Swaroop, C. H.
??:
:shiiuen
67
WU\HOVH
(QWHUVRPHWKLQJ!
(QWHUVRPHWKLQJ!DE
1RH[FHSWLRQZDVUDLVHG
11.3.1.1
/
ShortInputException
length
atleast
except
/
except
length
atleast
Swaroop, C. H.
??:
:shiiuen
68
11.4
try..finally
finally
try
except
finally
11.4.1
?
?
finally
?
11.3
??
finally
WU\
ILQDOO\
3URJUDPPLQJLVIXQ
:KHQWKHZRUNLVGRQH
&OHDQLQJXSFORVHGWKHILOH
7UDFHEDFNPRVWUHFHQWFDOOODVW
11.4.1.1
time.sleep
2
Python
Ctrl-c
/
Swaroop, C. H.
??:
:shiiuen
69
KeyboardInterrupt
finally
12.
Python
12.1
??
Python
Python
Python
Python
Python
12.2
sys
sys
sys.argv
12.2.1
?
12.1
??
sys.argv
GHIUHDGILOHILOHQDPH
LIOHQV\VDUJY
Swaroop, C. H.
??:
:shiiuen
70
2SWLRQVLQFOXGH
HOVH
1RDFWLRQVSHFLILHG
2SWLRQVLQFOXGH
9HUVLRQ
8QNQRZQRSWLRQ
3URJUDPPLQJLVIXQ
:KHQWKHZRUNLVGRQH
Swaroop, C. H.
??:
:shiiuen
71
12.2.1.1
Linux/Unix
cat
Python
sys.argv
sys.argv[0]
???
Python
?
0
--version
--help
sys.exit
help(sys.exit)
cat
concatenate
/
12.2.2
sys
sys.version
Python
sys.version_info
Python
!!!LPSRUWV\V!!!V\VYHUVLRQ
2FW
+DW
!!!V\VYHUVLRQBLQIR
sys
sys.stdin
?
sys.stdout
sys.stderr
12.3
os
Linux
Windows
os.sep
os
z
os.name
Windows
'nt'
Linux/Unix
'posix'
?
Swaroop, C. H.
??:
:shiiuen
72
z
os.getcwd()
Python
z
os.getenv()
os.putenv()
z
os.listdir()
z
os.remove()
z
os.system()
shell
z
os.linesep
Windows
??
'\r\n'
?
Linux
??
'\n'
?
Mac
??
'\r'
?
z
os.path.split()
z
os.path.isfile()
os.path.isdir()
os.path.existe()
Python
help(sys)
ㄝㄝ?
13.
Python
Python
Python
Python
?
13.1
__init__
__del__
x[key]
__getitem__()
Python
list
?
Python
?
13.1
__init__(self,...)
__del__(self)__str__(self)
print
str()
__lt__(self,other)
????
<
+
?
>
ㄝㄝ?
__getitem__(self,key)
??
x[key]
__len__(self)
len()
13.2
100
Swaroop, C. H.
??:
:shiiuen
73
!!!LIIODJSULQW@
OLVWWZR >LIRULLQOLVWRQHLIL!@
>@
13.3.1.1
if i > 2
2*i
?
13.4
*
**
Swaroop, C. H.
??:
:shiiuen
74
!!!SRZHUVXP
!!!SRZHUVXP
args
*
args
**
/
13.5
lambda
lambda
?
13.2
??
lambda
GHIPDNHBUHSHDWHUQ
SULQWWZLFHZRUG
SULQWWZLFH
ZRUGZRUG
13.5.1???
make_repeater
lambda
lambda
print
lambda
Swaroop, C. H.
??:
:shiiuen
75
13.6
exec
eval
exec
Python
Python
???
exec
+HOOR:RUOG
eval
Python
!!!HYDO
13.7
assert
assert
assert
assert
AssertionError
?
!!!P\OLVWSRS
7UDFHEDFNPRVWUHFHQWFDOOODVW
$VVHUWLRQ(UURU
13.8
repr
repr
eval(repr(object)) == object
?
!!!L >@
!!!LDSSHQGLWHP
!!!UHSUL
repr
__repr__
repr
14.
Python
Python
Python
Swaroop, C. H.
??:
:shiiuen
76
?
/
cPickle
Python
Python
14.1
??
Python
?
GUI
Python
GUI
Python
IrfanView
?
Kuickshow
Python
C
?
C++
Python
?
GUI
?
PyQt
Qt
Python
Qt
KDE
Qt
Qt Designer
Qt
Linux
Windows
??????
PyQt
Linux/Unix
GPL
PyQt
Python
???
GUI
???
Qt
PyGTK
GTK+
Python
GTK+
GNOME
GTK+
GUI
Glade
GTK+
Linux
Windows
GTK+
wxPython
wxWidgets
Python
wxPython
Linux
?
Windows
?
Mac
wxPython
?
IDE
GUI
SPE
?
Santi's Python Editor
wxGlade
???
GUI
wxPython
TkInter
GUI
IDLE
TkInter
PythonWare.org
??
TkInter
TkInter
Linux/Unix
Windows
TkInter
Python
Python.org
??
GUI
??
wiki
义?
Swaroop, C. H.
??:
:shiiuen
77
14.1.1
GUI
Python GUI
GUI
Linux
??
Windows
Linux
??
KDE
GNOME
*8,
Z[3\WKRQ
E\WHRIS\WKRQ
本文档为【简明Python教程(重新排版打印版)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。