-
列表字典組合
# coding=utf-8
stus = []
stu1 = {"no":"111","name":"張三","age":23,"nation":"漢","birthday":"1998-01-01","father":{"name":"張建國(guó)","company":"中國(guó)移動(dòng)","job":"客戶經(jīng)理"},"mother":{"name":"吳燕玲","company":"師大附中","job":"語(yǔ)文老師"}}
stus.append(stu1)
print(stus)
name = stus[-1]["name"]
print(name)
stu2 = {"no":"112","name":"李四","age":23,"nation":"漢","birthday":"1998-01-01","father":{"name":"李建國(guó)","company":"中國(guó)聯(lián)通","job":"客戶經(jīng)理"},"mother":{"name":"張麗麗","company":"人民醫(yī)院","job":"外科醫(yī)生"}}
stus.append(stu2)
print(stus)
name = stus[-1]["name"]
print(name)
fatherName = stus[-1]["father"]["name"]
print(fatherName)
查看全部 -
列表字典組合
# coding=utf-8
stus = []
stu1 = {"no":"111","name":"張三","age":23,"nation":"漢","birthday":"1998-01-01","father":{"name":"張建國(guó)","company":"中國(guó)移動(dòng)","job":"客戶經(jīng)理"},"mother":{"name":"吳燕玲","company":"師大附中","job":"語(yǔ)文老師"}}
stus.append(stu1)
print(stus)
name = stus[-1]["name"]
print(name)
stu2 = {"no":"112","name":"李四","age":23,"nation":"漢","birthday":"1998-01-01","father":{"name":"李建國(guó)","company":"中國(guó)聯(lián)通","job":"客戶經(jīng)理"},"mother":{"name":"張麗麗","company":"人民醫(yī)院","job":"外科醫(yī)生"}}
stus.append(stu2)
print(stus)
name = stus[-1]["name"]
print(name)
fatherName = stus[-1]["father"]["name"]
print(fatherName)
查看全部 -
列表字典組合
# coding=utf-8
stus = []
stu1 = {"no":"111","name":"張三","age":23,"nation":"漢","birthday":"1998-01-01","father":{"name":"張建國(guó)","company":"中國(guó)移動(dòng)","job":"客戶經(jīng)理"},"mother":{"name":"吳燕玲","company":"師大附中","job":"語(yǔ)文老師"}}
stus.append(stu1)
print(stus)
name = stus[-1]["name"]
print(name)
stu2 = {"no":"112","name":"李四","age":23,"nation":"漢","birthday":"1998-01-01","father":{"name":"李建國(guó)","company":"中國(guó)聯(lián)通","job":"客戶經(jīng)理"},"mother":{"name":"張麗麗","company":"人民醫(yī)院","job":"外科醫(yī)生"}}
stus.append(stu2)
print(stus)
name = stus[-1]["name"]
print(name)
fatherName = stus[-1]["father"]["name"]
print(fatherName)
查看全部 -
#鍵值對(duì)存儲(chǔ)key不能重復(fù),value可以重復(fù)
# coding=utf-8
lisa = {"name":"Lisa","age":23}
print(lisa)
print(lisa["age"])
lisa["age"] = 26
lisa["height"] = 166
print(lisa)
lisa.pop("age")
print(lisa)
查看全部 -
左閉右開(kāi)[0:2]取第一個(gè)和第二個(gè)
反向索引最后一個(gè)下標(biāo)是-1
# coding=utf-8
books = ["紅樓夢(mèng)","三國(guó)演義","水滸傳","西游記","聊齋志異"]
print(books[0:4])
print(books[0:-1])
查看全部 -
# coding=utf-8
books = ["紅樓夢(mèng)","三國(guó)演義","水滸傳","西游記","聊齋志異"]
print(books[0])
查看全部 -
int取整
%取余
# coding=utf-8
n=154
a=int(n/100)
b=int(n%100/10)
c=n%10
print(a)
print(b)
print(c)
re=a*a*a+b*b*b+c*c*c
if n==re:
print(n,end="")
print("是水仙花數(shù)")
else:
print(n,end="")
print("不是水仙花數(shù)")
154除以100取余54,54除以10等于5.4取整為5
查看全部 -
# coding=utf-8
score = 30
if score >=60:
print("考試通過(guò)!")
if score >= 90:
print("名列前茅,重點(diǎn)表?yè)P(yáng)")
else:
print("繼續(xù)努力,潛力巨大")
else:
print("考試未通過(guò),還需努力")
注意縮進(jìn)
查看全部 -
整型(整數(shù))不需要加雙引號(hào),加了雙引號(hào)就是字符串
查看全部 -
雙引號(hào)一定標(biāo)識(shí)字符串
查看全部 -
# coding=utf-8
la = "德語(yǔ)"
if la == "德語(yǔ)" :
print("Ich liebe dich")
elif la == "韓語(yǔ)" :
print("???")
elif la == "英語(yǔ)" :
print("I love you")
else :
print("我愛(ài)你")
由于是用記事本打開(kāi)編輯的所以對(duì)編碼有要求最終保存為utf-8 文件開(kāi)頭對(duì)應(yīng)utf-8? ?猜測(cè)是這個(gè)原因,也許我用個(gè)正經(jīng)編輯器就不會(huì)這樣
查看全部 -
注意 () not and or的優(yōu)先級(jí)
# coding=gbk
r1 = 1 != 1 or 8 < 2 and 6? > 3
print(r1)
r2 = 1 != 1 or not 8 < 1 and 6 > 3
print(r2)
r3 = 1 != 1 or not (8 < 1 and 6 > 3)
print(r3)
x = 700
re = (1000 - x) * 30
print(re)
if(re >= 1 and re <= 10000) :
print("結(jié)果落在區(qū)間內(nèi)")
else :
print("結(jié)果未落在區(qū)間內(nèi)")
查看全部 -
# coding=gbk
x=1600
re = (1000-x)*30
print(re)
if re >10000 :
print("結(jié)果大于10000")
else :
print("結(jié)果小于10000")
True False? 首字母是大寫(xiě)的
查看全部 -
# coding=gbk
if 8 > 6 :
print("判斷條件成立")
else :
print("判斷條件不成立")
查看全部 -
yntaxError: Non-ASCII character '\xe5' in file index.py on line 7, but no encoding declared; see http://python.org/dev/p
開(kāi)頭加# -*- coding: UTF-8 -*-
不好使就加#coding=gbk? 總有一款適合你
查看全部
舉報(bào)