在List內使用方法,其實跟String內使用方法,很像
一樣的首先,建立一個list,然後我們來看看33在Python 是第幾個index,這時要使用"方法"index()
# Create list areas # Print out the index of the element 33 |
答案是3,因為對於Python來紓,11的index是0
3 |
那我們再來數數看21在裡面出現幾次,使用"方法"count()
# Print out how often 21 appears in areas print(areas.count(21)) |
答案是2囉
2 |
文章標籤
全站熱搜