一、數(shù)據(jù)類型
公司主營(yíng)業(yè)務(wù):網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。成都創(chuàng)新互聯(lián)推出寶興免費(fèi)做網(wǎng)站回饋大家。
數(shù)字類型:
整型int
用來(lái)表示:等級(jí),年齡,×××號(hào),學(xué)號(hào),id號(hào)
level=10 print(type(level),id(level),level)1993698608 10
#浮點(diǎn)型float
#用來(lái)表示:身高,體重,薪資
salary=3.1 height=1.80 print(id(salary),type(height),salary) 29968815930403.1
# 字符串str:包含在引號(hào)(單引號(hào),雙引號(hào),三引號(hào))內(nèi)的一串字符
# 用來(lái)表示:名字,家庭住址,描述性的數(shù)據(jù)
name='egon' sex="woman" des="""hobby:man,play,read""" print(name,sex,des,type(name),type(sex),type(des)) egon woman hobby:man,play,read
#字符串拼接:+,*
# s1='hello ' # s2="word" # print(s1+s2) hello word # s3="""s_jun """ # print(s3*3) s_jun s_jun s_jun
#列表:定義在[]中括號(hào)內(nèi),用逗號(hào)分隔開(kāi)多個(gè)值,值可以是任意類型
#用來(lái)存放多個(gè)值:多個(gè)愛(ài)好,多個(gè)人名
stu_names=['egon','hobby','age'] print(id(stu_names),type(stu_names),stu_names,stu_names[1]) 2389078272136['egon', 'hobby', 'age'] hobby user_info=['egon',18,['read','music','play','dancing']] print(user_info[2][1]) music
#字典:定義{}內(nèi)用逗號(hào)分隔開(kāi),每一個(gè)元素都是key:value的形式,其中value可以是任意類型,而key一定要是不可變類型
user_info={'name':'egon','age':18,'hobbies':['read','music','dancing','play']} print(type(user_info),user_info['name'],id(user_info),user_info['hobbies'][3])egon 2025116757160 play
info={ 'name':'egon', 'hobbies':['play','sleep'], 'company_info':{ 'name':'Oldboy', 'type':'education', 'emp_num':40, } } print(info['company_info']['name']) Oldboy
students=[ {'name':'alex','age':38,'hobbies':['play','sleep']}, {'name':'egon','age':18,'hobbies':['read','sleep']}, {'name':'wupeiqi','age':58,'hobbies':['music','read','sleep']}, ] print(students[1]['hobbies'][0])
students={ 'alex':{ 'age':84, 'hobbies':['play','sleep'] }, 'egon':{ 'age':18, 'hobbies':['play',] } } print(students['egon']['age']) 18
#布爾類型bool:True,F(xiàn)alse
#用途:判斷
age_of_oldboy=18 inp_age=input('your age: ') inp_age=int(inp_age) if inp_age > age_of_oldboy: print('猜大了') elif inp_age < age_of_oldboy: print('猜小了') else: print('猜對(duì)了')
# 布爾類型的重點(diǎn)知識(shí)?。。。核袛?shù)據(jù)類型,自帶布爾值
#只有三種類型的值為False
# 0
# None
# 空:'',[],{}
if '': print('0===>') if []: print('[]') if {}: print('{}') if None: print('0===>None') if 0: print('00')
#其余全部為真
if ['',]: print('1====>') if {'':'',}: print('2===?') if True: print('3===>?')
# 可變類型與不可變類型
# 可變:在id不變的情況,值可以改變
×××:
x=1 print(id(x),type(x),x) x=2 print(id(x),type(x),x) ----------------------------------- 19936983201 1993698352 2
列表:
x=['a','b','c'] print(id(x),type(x),x) x[2]=10 print(x) print(id(x),type(x),x) --------------------------------- 2467516409224['a', 'b', 'c'] ['a', 'b', 10] 2467516409224 ['a', 'b', 10]
字典:
dic={'x':1,'y':2} print(id(dic),type(dic),dic) dic['x']=111111111 print(id(dic),type(dic),dic)
# 不可變類型:數(shù)字,字符串
# 可變類型:列表,字典
# dic={[1,2,3]:'a'}
二、格式化輸出
name="s_jun" age=20 print('my name is %s my age is %s' %(name,age)) my name is s_jun my age is 20
print('my name is %s my age is %s'%('egon',18)) print('my name is %s my age is %d'%('egon',18)) x='my name is %s my age is %d' %('egon',18) print(x) ----------------------------------- my name is egon my age is 18 my name is egon my age is 18 my name is egon my age is 18
name="s_jun" msg=""" ------------ info of %s ----------- Name : %s ------------- end ----------------- """%(name,name) print(msg) ------------------------------------------------------------------------ ------------ info of s_jun ----------- Name : s_jun ------------- end -----------------
age=20 A=' %s '%(age) print(A) ------------------------------------- 20
三、基本運(yùn)算符
print(10/3) print(10//3) print(10%3) print(3**3) ----------------------- 3.3333333333333335 3 1 27
增量賦值
age=18 age+=2 # age=age+2 print(age) age-=10 #age=age-10 print(age) ----------------------- 20 10
#邏輯運(yùn)算
#and:邏輯與,and用于連接左右兩個(gè)條件,只有在兩個(gè)條件判斷的結(jié)果都為T(mén)rue的情況下,and運(yùn)算最終的結(jié)果才為T(mén)rue
print(1 > 2 and 3 > 4) print(2 > 1 and 3 > 4) print(True and True and True and False) ------------------------------------------- False False False
#or:邏輯或,有一個(gè)為真結(jié)果就為真
print(True or False) print(True or False and False) print((True or False) and False) print(not 1 > 2) ------------------------------------ True True False True
四、流程控制之if
sex='female' age=20 is_beutiful=True if sex == 'female' and age > 18 and age < 26 and is_beutiful: print('表白....') -------------- 表白....
sex='female' age=20 is_beutiful=True if sex == 'female' and age > 18 and age < 26 and is_beutiful: print('表白....') else: print('阿姨好') ------------------------------- 表白....
age_of_oldboy=18 inp_age=input('your age: ') inp_age=int(inp_age) if inp_age > age_of_oldboy: print('猜大了') elif inp_age < age_of_oldboy: print('猜小了') else: print('猜對(duì)了')
username='s_jun' password='123' inp_name=input('name>>: ') inp_pwd=input('password>>: ') if inp_name == username and inp_pwd == password: print('login successfull') else: print('user or password not vaild')
sex='female' age=20 is_beutiful=True is_successful=False if sex == 'female' and age > 18 and age < 26 and is_beutiful: print('表白....') if is_successful: print('在一起') else: print('對(duì)不起,我也不喜歡你,我逗你玩呢...') else: print('阿姨好') ------------------------------------------ 表白.... 對(duì)不起,我也不喜歡你,我逗你玩呢...
''' 如果:成績(jī)>=90,那么:優(yōu)秀 如果成績(jī)>=80且<90,那么:良好 如果成績(jī)>=70且<80,那么:普通 其他情況:很差 ''' score=89 if score >= 90: print('優(yōu)秀') elif score >= 80: print('良好') elif score >= 70: print('普通') else: print('很差') ----------------------- 良好
五、流程控制之while
while:條件循環(huán)
import time count=1 while count < 3: print('=====>',count) time.sleep(0.1)
count=1 while count <= 3: print('=====>',count) count+=1
#break:跳出本層循環(huán)
age_of_oldboy=18 while 1: inp_age=input('your age: ') inp_age=int(inp_age) if inp_age > age_of_oldboy: print('猜大了') elif inp_age < age_of_oldboy: print('猜小了') else: print('猜對(duì)了') break
age_of_oldboy=18 count=0 while count < 3: inp_age=input('your age: ') inp_age=int(inp_age) if inp_age > age_of_oldboy: print('猜大了') elif inp_age < age_of_oldboy: print('猜小了') else: print('猜對(duì)了') break count+=1 print('猜的次數(shù)',count)
age_of_oldboy=18 count=0 while True: if count == 3: print('try too many times') break inp_age=input('your age: ') inp_age=int(inp_age) if inp_age > age_of_oldboy: print('猜大了') elif inp_age < age_of_oldboy: print('猜小了') else: print('猜對(duì)了') break count+=1 print('猜的次數(shù)',count)
#continue:跳過(guò)本次循環(huán),進(jìn)入下一次循環(huán)
count=1 while count < 5: #3 if count == 3: count += 1 continue print(count) count+=1
while True: print('=========>') continue print('=========>') print('=========>') print('=========>')
while True: inp_name=input('name>>: ') inp_pwd=input('password>>: ') if inp_name == "s_jun" and inp_pwd == "123": print('login successfull') while True: cmd=input('cmd>>>: ') if cmd == 'quit': break print('%s 命令正在執(zhí)行...' %cmd) break else: print('user or password not vaild')
tag=True while tag: inp_name=input('name>>: ') inp_pwd=input('password>>: ') if inp_name == "s_jun" and inp_pwd == "123": print('login successfull') while tag: cmd=input('cmd>>>: ') if cmd == 'quit': tag=False continue # break print('%s 命令正在執(zhí)行...' %cmd) else: print('user or password not vaild')