#單行注釋
'''****************************
?*********多行注釋***************
?*******************************?
function: calc area of triangle?
*******************************?'''
print 'this program will calc the area of triangle'
print "program start"
print '''*********************?******************'''
triA = input("pls input a of tri:")
triH = input('pls input h of tri:')
if triA >= 0 and triH >= 0:
triArea = triA*triH/2.0
print ("面積是%.2f"%(triArea))
- 注釋
用于提高代碼可讀性的輔助性文字魄衅,不被執(zhí)行
單行
''' 三個連續(xù)的單引號 丸相,多行注釋
- 縮進
一行代碼開始前的空白區(qū)域,表達程序的格式框架杆烁,同一縮進的屬于同一層級。
一般用4個空格或1個TAB - 變量
程序中用于保存和表示數(shù)據(jù)的符號
變量采用標識符(名字)來表示简卧,可以用等號(=)向變量復制或者修改
注意: 大小寫敏感兔魂,首字符不能是數(shù)字、不與保留字相同 - 變量類型
常見的有:整形(1举娩、2析校、3),浮點型(1.0铜涉、2.1)智玻,字符串('hello'),復數(shù)(1+2j)
可以用type(變量) 來查看 - 函數(shù)
比如這里的input() print()
根據(jù)輸入?yún)?shù)產(chǎn)生不同輸出的功能骄噪,類似與數(shù)學中的函數(shù)