[Python] List 的用法

index與count方法

  • index(內容) : 找到內容所在的索引值
  • count(內容) : 計算該內容的次數



score = [90, 81, 70, 68, 92, 70, 77, 70]
print("第一個70分的學生是編號%d號" %(int(score.index(70))+1))
print("70分的學生共有%d位" % score.count(70))
第一個70分的學生是編號3號
70分的學生共有3位

in與not in


animal = ["dog", "cat", "elephone", "bird"]
if "dog" in animal:
    print("dog已在串列中")
else:
    animal.append("dog")

if "snake" not in animal:
    animal.append("snake")
    print("已新增snake")
else:
    print("snake已在串列中")
dog已在串列中
已新增snake

留言

這個網誌中的熱門文章

[HTML]標籤-下

論P, NP, NP-Complete, NP-Hard問題

[Python]基礎課程

[系統]解除電腦限制頻寬

[HTML]標籤-上

[AlaSQL] 多data查詢+累計

How to Check the MySQL Version

[SQL Sever] 日期時間

推薦使用的9款編程字體

類別型態 vs 基本型態