怎麼叫起python呢?只要在命令列打python,就會進入python的互動模式。
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>strA="3 times"
>>>strA * 3
'3 times3 times3 times'
>>>strB="""I can't know that"""
>>>strB
“I can’t know that”
現在來寫看你第一個Python程式吧!
第一個Python:
目標:寫一個method,可以接受Inerger或是string的引數
-----------------------easy.py----------------
import types--------------end easy.py--------------
def poly(argv):
if type(argv)==types.IntType:
print "This is Int"
elif type(argv)==types.StringType:
print "This is String"
else:
print "I can't recognize"
if __name__=="__main__":#如果使用命令列模式啟動,會到這裡執行
inputdata=raw_input("Please Input something:")
poly(inputdata)
inputdata=input("Please input a integer:")
poly(inputdata)
將虛線中間的內容存成easy.py檔(要照著縮排,python用縮排來辨識區塊),接著執行python easy.py,執行畫面會如下:
E:\>python easy.py
Please Input something:KKlldki""afds
This is String
Please input a integer:892019
This is Int
No comments:
Post a Comment