def add(a,b):
return a+b
print add(1,2)
print add('abc', 'def')
print add([1, 2, 3], [4, 5, 6])
3 abcdef [1, 2, 3, 4, 5, 6]
a=[12, 'abcde', 4+2j, [3,4,5]]
a.append('add')
print a;
[12, 'abcde', (4+2j), [3, 4, 5], 'add']
print 4+5
print "Hello World!"
9 Hello World!
print 4 + 5
print 12 - 32
print (4 + 5) * 6
print 4 + 5 * 6
print
print 9 / 5 # 정수/정수 연산 결과는 정수. 그래서 몫만 계산결과로 나온다.
print - (9 / 5)
print
print 9.0 / 5.0
print 9 / 5.0
print
print 9.0 // 5.0 # 몫 연산자
print
print 2 ** 3
9 -20 54 34 1 -1 1.8 1.8 1.0 8
print -9 / 5
print 5 * (-2) + 1
-2 -9
print 9 % 5
print -9 % 5
4 1
print 1 / 2
print -1 / 2
print 1 / -2
print -1 / -2
0 -1 -1 0
print divmod(9, 5)
a, b = divmod(9, 5)
print a
print b
print
c, d = (10, 11)
print c
print d
(1, 4) 1 4 10 11
print divmod(1, 2)
print divmod(-1, 2)
print divmod(1, -2)
print divmod(-1, -2)
(0, 1) (-1, 1) (-1, -1) (0, -1)
print 5.
print 5.0
print 5.4e10
print 5e10
print -5e-3
5.0 5.0 54000000000.0 50000000000.0 -0.005
import sys
print sys.maxint
print -sys.maxint-1
9223372036854775807 -9223372036854775808
print 'Hello'
print "Hi there!"
Hello Hi there!
a = 'My name is '
b = 'Amenda'
print a + b
My name is Amenda
raise SystemExit
An exception has occurred, use %tb to see the full traceback.
SystemExit
To exit: use 'exit', 'quit', or Ctrl-D.
import sys
print sys.version
print
print sys.version_info
2.7.6 | 64-bit | (default, Jun 4 2014, 16:42:26) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)
# file: cal.py
import calendar
calendar.prmonth(2014, 9)
import os
print os.getcwd() #ipython 실행후 프롬프트에서 %pwd
print
%run /Users/yhhan/git/ipython/cal.py #cmd 창 내에서 해당 폴더로 이동 후 ipython cal.py
/Users/yhhan/git/jms September 2014 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
execfile('/Users/yhhan/git/python/cal.py')
September 2014 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/bin/env python
#file: modfile.py
s = 'module file sample'
def add(a, b):
return a+b
print add(3,4)
import modfile
modfile.s
modfile.add(8,9)
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-44-42555e456c61> in <module>() ----> 1 import modfile 2 modfile.s 3 modfile.add(8,9) ImportError: No module named modfile
from turtle import *
reset()
forward(100)
left(90)
forward(100)
left(90)
forward(100)
left(90)
forward(100)
left(90)
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5,6], [1,4,9,16,25,36])
plt.ylabel('some numbers')
plt.show()
help(sys)
?sys
help(sys.exit)
?sys.exit