函式 function
何謂函式(function)? help() 與 print() 都是 Python 的內建函式
http://faculty.msmary.edu/heinold/Introduction_to_Programming_Using_Python_Heinold.pdf
In [ ]:
help(print)
In [ ]:
help(help)
In [ ]:
# 列印 Python 系統的版次與關鍵字
import sys
import keyword
print("Python version: ", sys.version_info)
print("Python keywords: ", keyword.kwlist)
In [ ]:
# 字串, 整數, 浮點數
help(str)
help(int)
help(float)
In [ ]:
import random
dir(random)
In [ ]:
help(dir)
In [ ]:
for i in 2, 4, 6, 8:
print(i)
In [ ]:
# 讓圖直接 show 在 output
%matplotlib inline
import matplotlib.pyplot as plt
vals = [3,2,5,3,1]
plt.plot(vals)
# 在 server 中, 以視窗顯示 plt
#plt.show()
In [ ]:
temp = eval(input('Enter a temperature in Celsius: '))
print('In Fahrenheit, that is', 9/5*temp+32)
In [ ]:
%matplotlib inline
from pylab import plot,ylim,xlabel,ylabel,show
from numpy import linspace,sin,cos
x = linspace(0,10,100)
y1 = sin(x)
y2 = cos(x)
plot(x,y1,"k-")
plot(x,y2,"k--")
ylim(-1.1,1.1)
xlabel("x axis")
ylabel("y = sin x or y = cos x")
In [ ]:
for c in [0b1001000, 0b1100101, 0b1101100, 0b1101100,
0b1101111, 0b0100000, 0b1010111, 0b1101111, 0b1110010,
0b1101100, 0b1100100, 0b0100001, 0b0001010]:
print(chr(c), end="")
In [ ]: