Python程式設計從入門到實踐自我整合 第七章

2021-09-12 01:12:54 字數 550 閱讀 2748

7.1 函式input()的工作原理

函式input()讓程式暫停執行,等待使用者輸入一些文字。

message = input(「tell me something,and i will repeat it back to you:」)

print(message)

7.1.1 編寫清晰的程式

每當你使用函式input()時,都應指定清晰而明白的提示。

7.1.2 用int()來獲取數值輸入

用input()獲取的輸入為字串,

age = input(「how old are you?」)

age = int(age)

7.1.3 求模運算

求模運算子(%)將兩個數相除並返回餘數

7.2 while迴圈簡介

while a:

print(「hello !」)

while迴圈中使用break語句立即退出while迴圈

任何python迴圈中都可以使用break退出迴圈

在迴圈中使用continue語句,退出本次迴圈,直接進行下一次迴圈。

Python 程式設計 從入門到實踐

1.官網安裝 3.環境配置 務必選中核取方塊add python to path 4.檢視 啟動python版本的命令 python 執行 print hello python world 5.終端執行x.py檔案 python x.py 7.檢視當前目錄中的所有檔案的命令 dir windows系...

Python程式設計從入門到實踐 基礎入門

python程式設計從入門到實踐 基礎入門 1 python中的變數 2 python首字母大寫使用title 方法,全部大寫upper 方法,全部小寫lower 方法 3 python中字串拼接使用 號 4 python中刪除字串的空格 刪除末尾空格的rstrip 刪除開頭空格的lstrip 刪除...

Python程式設計 從入門到實踐 1

內容總結自 python程式設計 從入門到實踐 安裝python3 安裝文字編輯器sublime text並配置python3環境 安裝sublime text tools new build system 將 untitled.sublime build 文件中的所有內容刪除,輸入以下內容 注意,...