python基礎管理 IF

2021-09-29 20:50:31 字數 1894 閱讀 2192

1 簡單的例子

# -*- coding:utf-8 -*-

cars = ['audi','bmw','subaru','tiyoa']

for car in cars:

if car == 'bmw':

print(car.upper())

else:

print(car.title())

2 條件測試

car == 'bmw': 為布林條件,返回為true和false。

true

>>> a

'123'

>>> 

>>> a!='234'   --不等條件

true

>>> a!='123'

false

>>> 

數字判斷

>>> a=10

>>> a>100

false

>>> a<10

false

>>> a=10

>>> a==10

true

>>> a<=10

true

>>> a>=10

true

>>> a>=10 and a<=10

true

>>> a>=10 or a<=10

true

>>>

判斷是否在列表或元組中

>>> a=('a','b','c')

>>> 'a' in a

true

>>> 'd' in a

false

>>>'d' in a and 'c' in a

false

>>> 'd' in a or 'c' in a

true

>>>

a=

if a                     #如果列表a為空則回值 true否則為false

print('list a is null')

else:

for b in a

print(b)

或者

a=b=len

if b==0

print('list '+b+' is empty')

語句案例 :

-bash-4.2$ vi age.py

age=20

if age<12:

print('your age<12 free,lol')

elif age==12:

print('your age=12 $100,thanks,****')

else:

print('your age>12 $1000,thanks,****')

~

Python基礎 名片管理系統

解析 分為兩個檔案,main.py和tools.py,main是主幹,tools是定義的函式,進行匯入 tools 是自己定義的乙個模組,裡面寫了較多的函式 為了減少主 的臃腫和方便後期新增功能 因為是直接使用makdown書寫的博文,所以有可能 在注釋的地方會出現縮排上的問題,可以稍微改下,麻煩了...

python基礎 習題 學生管理系統

info def print info print 歡迎使用學生資訊管理系統v1.0 print 1.新增資訊 print 2.修改資訊 print 3.刪除資訊 print 4.查詢資訊 print 5.遍歷資訊 print 6.退出 print 歡迎使用學生資訊管理系統v1.0 def add ...

Python基礎實踐 密碼管理系統例項

需求分析 1.主介面 選項 密碼生成,密碼查詢,密碼修改,密碼刪除 2.密碼生成 使用者輸入密碼的描述,輸入密碼的長度,使用隨機數生成乙個比較複雜的密碼,並且儲存在列表中 4.密碼修改,先查找到,然後提示使用者輸入新的密碼,確定後儲存 001版本 面向過程版本 1.編寫乙個主函式,五個自定義函式,分...