Python程式設計 從入門到實踐 練習5 1 5 2

2021-10-07 18:54:26 字數 3431 閱讀 8232

#檢查兩個字串相等或不等

print

("is car == 'subaru'? i predict true."

)print

(car ==

'subaru'

)print

("\nis car == 'audi'? i predict false."

)print

(car ==

'audi'

)print

("\nis car != 'subaru'? i predict false."

)print

(car !=

'subaru'

)print

("\nis car != 'audi'? i predict true."

)print

(car !=

'audi'

)#檢查兩個數字相等、不等、大於、小於、大於等於和小於等於

age =

18print

("\nis his age > 18? i predict false."

)print

(age >18)

print

("\nis his age < 18? i predict false."

)print

(age <18)

print

("\nis his age >= 18? i predict true."

)print

(age >=18)

print

("\nis his age <= 18? i predict true."

)print

(age <=18)

print

("\nis his age == 18? i predict true."

)print

(age ==18)

print

("\nis his age != 18? i predict false."

)print

(age !=18)

#使用函式lower()的測試

name =

'alice'

print

("\nis name.lower() == 'alice'? i predict true"

)print

(name.lower()==

'alice'

)print

("\nis name.lower() == 'bob'? i predict false"

)print

(name.lower()==

'bob'

)#使用關鍵字and和or的測試

print

("\nis name == 'alice' and car == 'audi'? i predict false"

)print

(name ==

'alice'

and car ==

'subaru'

)print

("\nis name == 'alice' or car == 'audi'? i predict true"

)print

(name ==

'alice'

or car ==

'subaru'

)#測試特定的值是否包含在列表中

cars =

['subaru'

,'audi'

]print

("\nis car in cars? i predict true"

)print

(car in cars)

new_car =

'bmw'

print

("\nis new_car in cars? i predict false"

)print

(new_car in cars)

#測試特性的值是否未包含在列表中

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 文件中的所有內容刪除,輸入以下內容 注意,...