iT邦幫忙

2024 iThome 鐵人賽

DAY 6
1

今天也繼續加油、繼續刷刷刷~
題目1:創建列表並打印

-列表是一組有序的元素,可以存放各種數據
-我們可以創建一個列表,然後用 print() 函數把它顯示出來

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371qYs8zeM8LI.png
https://ithelp.ithome.com.tw/upload/images/20240920/201683716dcKmB9Y0o.png

第1題結束。
————————————我是可愛的題目分隔線————————————

題目2:計算列表元素的和

-列表裡的元素可以是數字,我們可以用 sum() 函數計算這些數字的總和

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371oJRllEOdnn.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371xMkOy2K6EE.png

第2題結束。
————————————我是可愛的題目分隔線————————————

題目3:找出列表中的最大值和最小值

-用 max()min() 函數可以輕鬆找到列表中的最大值和最小值

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371bbzf78dVrg.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371mC3vPTmnx1.png

第3題結束。
————————————我是可愛的題目分隔線————————————

題目4:列表元素翻轉

-我們可以用 reverse() 方法或切片語法來翻轉列表中元素的順序

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371zI3uuulnX3.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371Ii2NrnF7zB.png

第4題結束。
————————————我是可愛的題目分隔線————————————

題目5:列表元素去掉重複的元素

-列表裡可能有重複的元素,我們可以用 set() 來去重,然後轉回列表

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371XzNewIV2n6.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371ZYAWeKEAZz.png

第5題結束。
————————————我是可愛的題目分隔線————————————

題目6:合併兩個列表並排序

-可以把兩個列表用 + 合併,然後用 sorted() 排序

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371ue61WVv0gd.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371n0VFP3dIbS.png

第6題結束。
————————————我是可愛的題目分隔線————————————

題目7:列表元素的平方

  • 可以用 for 迴圈或列表推導式來計算每個元素的平方

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371jal6mqUGVt.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371GiAcNhZPaZ.png

第7題結束。
————————————我是可愛的題目分隔線————————————

題目8:列表中的偶數元素

-可以用條件篩選出列表中的偶數元素

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371ndEVDUAeNk.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371U3DMOQ1Bay.png

第8題結束。
————————————我是可愛的題目分隔線————————————

題目9:列表中所有字符串轉大寫

-用 str.upper() 方法可以把列表中的每個字符串都轉成大寫
https://ithelp.ithome.com.tw/upload/images/20240920/20168371AoYn5MgVbe.png
https://ithelp.ithome.com.tw/upload/images/20240920/20168371STILOowZa9.png

第9題結束。
————————————我是可愛的題目分隔線————————————

題目10:刪除列表中的指定元素

-可以用 remove() 方法刪除列表中第一次出現的指定元素

舉個例子:
https://ithelp.ithome.com.tw/upload/images/20240920/20168371eE52Xumdz7.png
https://ithelp.ithome.com.tw/upload/images/20240920/201683717GPgE7gHaU.png

第10題結束。
---距離集滿300題還剩240題---
————————————我是可愛的題目分隔線————————————


上一篇
第五天刷題
下一篇
第七天刷題
系列文
Python 新手入門:挑戰30天刷完300題13
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言