names=['wang','lili']
type(names)
names[0]
'wang'
names[1]
'lili'
1.list可以放任何東西
mylist["xiaomao",22,true,[4,6,7]]
mylist[-1][1]
顯示結果為【4,6,7】裡的6
mylist.insert(2,3)意思是在下標為2的數前插入乙個3
mylist[1,2,3,4,5]
mylist[1,2,3,4,5,6]
mylist.insert(3,7)
mylist[1,2,3,7,4,5,6]
mylist.count(3)
統計3在上面的列表中出現的次數
mylist.pop()
會刪除末尾的元素。
元組list是anble=['anble',18,'女',『舞蹈』]
元組是anble=(』anble』,18,『女』,『舞蹈』)
元組內容不能更改。
mytuple=(『am』)這是乙個str
mytuple=(『am』,)加個逗號就是元組了
mytuple=(『huluobo』,28,true,[80,80,80])元組可以訪問但不能修改。但是,裡面的list可以更改
mytuple[-1][2]
mytuple=(『huluobo』,28,true,[80,80,160])
判斷與迴圈
color=(『color』,28,[20,20,20],false)
if color[-1]==false:
print('姓名:',color[0],"性別:",「女性」)
if color[-1]!=true:
print(『單獨的if』」)
if color[-1]!=true:
print(『單獨的if』」)這個if就是屬於上乙個if的
必須有縮排。不然就會出問題。
python是通過縮進來進行判斷他是屬於哪個**塊
if :
elif:
else:
if color[1]>=30:
print("而立之年")
elif color[1]>=18
print("成年了")
else:
print(「」青少年「」)
作業:age=input(『請輸入你的年齡』)
#輸出你的出生年份
#他是不是90後
age=input('請輸入你的年齡:')
year=2017-int(age)
print("你的出生年份:",year)
if year>=1990:
print("你是個90後")
else:
print("你不是90後")
#1-100累加
這就講到迴圈了。while迴圈和for迴圈
for in
while
sum=0
for num in range(1,100):
sum+=num
num=100
while num>0:
print(num)
num-=1
明天課程:字典
作業2輸入年份,計算是否是閏年。
while -1:
year=int(input("請輸入乙個年份:"))
if (year%100)==0:
if(year%400)==0:
print('是閏年')
else:
print('不是閏年')
elif (year%4)==0:
print('是閏年')
else:
print("不是閏年")
python第三課答案 python第三課
字串操作 s alexwusir s1 s.capitalize 首字母大寫 print s1 全大寫,全小寫 s2 s.upper s21 s.lower print s2,s21 大小寫翻轉 s3 s.swapcase print s3 每個隔開 特殊字元或數字 的單詞首字母大寫 s alex ...
python第三課答案 python第三課筆記
以下哪個變數的命名不正確?為什麼?a mm 520 b mm520 c 520 mm d 520 mm 答 c不正確,不能數字開頭 在不上機的情況下,以下 你能猜到螢幕會列印什麼內容嗎?myteacher 小甲魚 yourteacher myteacher yourteacher 黑夜 print ...
python第三課答案 python第三課
1.迴圈物件,主要呼叫next 2.迭代器iterator 在理解上可以和迴圈物件理解為乙個東西。3.生成器 generator 自定義的迴圈物件。4.表推導 list comprehension 是快速生成表的方法。表推導用中括號。l x 2 for x in range 10 練習 f open...