#檢查兩個字串相等或不等
("is car == 'subaru'? i predict true."
(car ==
'subaru'
("\nis car == 'audi'? i predict false."
(car ==
'audi'
("\nis car != 'subaru'? i predict false."
(car !=
'subaru'
("\nis car != 'audi'? i predict true."
(car !=
'audi'
)#檢查兩個數字相等、不等、大於、小於、大於等於和小於等於
age =
18print
("\nis his age > 18? i predict false."
(age >18)
("\nis his age < 18? i predict false."
(age <18)
("\nis his age >= 18? i predict true."
(age >=18)
("\nis his age <= 18? i predict true."
(age <=18)
("\nis his age == 18? i predict true."
(age ==18)
("\nis his age != 18? i predict false."
(age !=18)
#使用函式lower()的測試
name =
'alice'
("\nis name.lower() == 'alice'? i predict true"
(name.lower()==
'alice'
("\nis name.lower() == 'bob'? i predict false"
(name.lower()==
'bob'
)#使用關鍵字and和or的測試
("\nis name == 'alice' and car == 'audi'? i predict false"
(name ==
'alice'
and car ==
'subaru'
("\nis name == 'alice' or car == 'audi'? i predict true"
(name ==
'alice'
or car ==
'subaru'
)#測試特定的值是否包含在列表中
cars =
['subaru'
,'audi'
("\nis car in cars? i predict true"
(car in cars)
new_car =
'bmw'
("\nis new_car in cars? i predict false"
(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 文件中的所有內容刪除,輸入以下內容 注意,...