第乙個Python程式(Day3)

2022-04-18 22:57:17 字數 2171 閱讀 7315

python直譯器執行python程式的過程

eg:python3 c:\ test.py

1.啟動python直譯器 (記憶體中)

2.將c:\ test.py中的內容從硬碟讀入記憶體

3.執行讀入記憶體的**

如果想要永久儲存**,就要用檔案的方式

如果想要直觀的除錯**,就用互動式的方式

(一)變數

乙個是變:  核心在於變化

乙個是量:  衡量,計量,表達的一種狀態

變數的定義

宣告乙個變數

eg:name = 「mr shao」

變數的定義規則

變數名只能是 字母、數字或下劃線的任意組合

變數名的第乙個字元不能是數字

以下關鍵字不能宣告為變數名['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

定義方式

駝峰體

ageofoldboy = 56 

numberofstudents = 80

下劃線

age_of_oldboy = 56number_of_students= 80

定義變數不好的方式舉例

變數名為中文、拼音

變數名過長

變數名詞不達意

(二)常量

常量即指不變的量,如pai 3.141592653..., 或在程式執行過程中不會改變的量

二    程式互動

————讀取使用者輸入

name = input("what is your name?")

print("hello"+name)

執行指令碼就會發現,程式會等待你輸入姓名後再往下繼續走。

可以讓使用者輸入多個資訊,如下

name = input("what is you name?")

age = input("how old are you?")

hometown = input("where are you from?")

print("hello",name,"you are"age,"yours old ,you came from",hometown)

執行輸出

what is your name?mr shao

how old are you?22

where is your hometown?shandong

hello mr shao your are 22 years old, you came from shandong

注釋

**注釋分單行和多行注釋, 單行注釋用#,多行注釋可以用三對雙引號""" """

3 第乙個Python程式

無論讀者使用的是哪種作業系統,相信都已經安裝好了 python 環境,可以通過命令列視窗或者 python 自帶的 idle 成功啟動互動式直譯器 如圖 1 所示 圖 1 啟動 python 互動式直譯器 本節將帶領讀者正式編寫第乙個 python 輸出 hello world 在圖 1 中的提示符...

3 第乙個python程式

學習任何一門語言的第一步,首先要寫個 hello world 這算是程式設計師的乙個傳統。但在寫之前,還有注意幾個問題。首先,python是一門指令碼語言,而指令碼語言的特點就是 我們寫的 會先由直譯器進行編譯以後,再去執行。但是當我們的程式執行在作業系統之上時,系統並沒有那麼智慧型,能夠自動識別出...

day01 第乙個python程式

安裝外掛程式 pip install 外掛程式名稱 conda install 外掛程式名稱 anaconda可用這個 python資料型別 數字 num int 有符號整數 float 浮點型 complex 複數 布林值 true false 字串 str 字典 dict 元祖 tuple 列表...