import keyword
print keyword.kwlist
print
print len(keyword.kwlist)
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield'] 31
print abs(3)
print abs(-3)
3 3
print max(1, 2)
print max([1, 2, 3])
print max("python")
2 3 y
print min(1, 2)
print min([1, 2, 3])
print min("python")
1 1 h
print pow(2, 4)
print pow(3, 3)
print pow(2, -1)
16 27 0.5
print chr(97)
print chr(65)
print chr(48)
a A 0
print str(3)
print str([1, 2])
3 [1, 2]
print range(10)
print range(3, 10)
print range(3, 10, 2)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [3, 4, 5, 6, 7, 8, 9] [3, 5, 7, 9]
print type(-1)
print type('abc')
print type([1, 2, 3])
<type 'int'> <type 'str'> <type 'list'>
print str(12345)
12345
str = 'abc'
print str(12345)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-2-ad06f2f248af> in <module>() 1 str = 'abc' 2 ----> 3 print str(12345) TypeError: 'str' object is not callable
a = 1
print a
1
print b
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-22-ab3a5d8f1075> in <module>() ----> 1 print b NameError: name 'b' is not defined
b = 2
print b
del b
print b
2
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-24-026dc2933af4> in <module>() 3 4 del b ----> 5 print b NameError: name 'b' is not defined
#이것은 주석입니다.
import sys #이것도 주석입니다.
a = 1
b = 3
if (a == 1) and \
(b == 3):
print 'connected lines'
connected lines
a = 1
b = 3
if (a == 1) and (b == 3):
print 'connected lines'
connected lines
a = 1
b = a
1 + 3 = a
File "<ipython-input-15-3aa35fdab4b7>", line 1 1 + 3 = a SyntaxError: can't assign to operator
a = 1
a = a + 1
print a
2
c, d = 3, 4
print c, d
x = y = z = 0
print x, y, z
e = 3.5; f = 5.6
print e, f
3 4 0 0 0 3.5 5.6
e = 3.5; f = 5.6
e, f = f, e
print e, f
5.6 3.5
a = (b = c + d)
File "<ipython-input-29-79d71c957091>", line 1 a = (b = c + d) ^ SyntaxError: invalid syntax
a = 1
a += 4
print a
5
a = 10
a -= 3
print a
7
a = 10
a *= 2+3
print a
50
a = [1,2,3]
b = [10, a, 20]
c = ['x', a, 'y']
print a
print b
print c
[1, 2, 3] [10, [1, 2, 3], 20] ['a', [1, 2, 3], 'b']
a[1] = 1000
print a
print b
print c
[1, 1000, 3] [10, [1, 1000, 3], 20] ['a', [1, 1000, 3], 'b']
name = raw_input('name?')
name?홍길동
print name
홍길동
k = int(raw_input('int : '))
print k
int : 12 12
i = input('int :')
print i
int :45 45
k = input('expr:')
print k
expr:30 + 50 80
print 4 + 5, 4 - 2
9 2
print 1; print 2
1 2
print 1,
print 2
1 2
print 12 + 'spam'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-71-84ee898a197b> in <module>() ----> 1 print 12 + 'spam' TypeError: unsupported operand type(s) for +: 'int' and 'str'
print '12' + 'spam'
12spam
참고 문헌: 파이썬(열혈강의)(개정판 VER.2), 이강성, FreeLec, 2005년 8월 29일