Python是有提供輸入和輸出的函數的print輸出input輸入(raw_input)
print
>>> print('hello word')
hello word
>>> print("hello word")
hello word
>>>
用print()在括號里加上字符串,就可以向屏幕上輸出指定的文字。
print也可以打印整數
>>> print(300)
300
>>> print(300 + 100)
400
>>> print('100 + 200 =', 100 + 200)
100 + 200 = 300
用單引號引起來的是字符串所以python解釋器會原樣輸出。後面的沒有引號所以會把他當成一個算式來計算
input
如果我們想讓用戶輸入要打印的東西那麼就要用到input
>>> cao = input('請輸入:');print(cao)
請輸入:1
1
>>>
從用戶的輸入獲取到cao的值,在打印cao分號上一條語句的結束符號