[問題] 新手Python 一些問題

看板Python作者 (Adam)時間7年前 (2018/08/08 13:43), 7年前編輯推噓3(303)
留言6則, 4人參與, 7年前最新討論串1/1
各位大大好,小弟剛入門Python,碰到一些問題,這code是在寫輸入自串英文跟數字, 然後依據順序輸出 code: word1=input() word2=input() word3=input() list1=word1.split(' ') list2=word2.split(' ') list3=word3.split(' ') if list1[1]>list2[1]: temp=list2 list2=list1 list1=temp if list1[1]>list3[1]: temp=list3 list3=list1 list1=temp if list2[1]>list3[1]: temp=list3 list3=list2 list2=temp print("{} {} {}.".format(list1[0],list2[0],list3[0])) 問題1:list1=word1.split(' '),括弧內為什麼不能這樣打('.') 問題2: temp=list2 list2=list1 list1=temp 這邊看不太懂是什麼意思? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 112.104.16.189 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1533706992.A.166.html

08/08 14:12, 7年前 , 1F
問題二是swap
08/08 14:12, 1F
感謝,我去研究研究

08/08 16:55, 7年前 , 2F
問題一你要先知道str.split是用來做什麼的 原本是用空
08/08 16:55, 2F

08/08 16:55, 7年前 , 3F
白去做分割
08/08 16:55, 3F

08/08 16:55, 7年前 , 4F
如果用.做分割的話 遇到小數就會有問題
08/08 16:55, 4F
謝謝 ※ 編輯: rxs80087 (36.224.53.201), 08/08/2018 18:09:58

08/09 03:31, 7年前 , 5F
python swap不需要用temp 一行解決就行了
08/09 03:31, 5F

08/10 21:48, 7年前 , 6F
補充五樓 x, y = y, x
08/10 21:48, 6F
文章代碼(AID): #1RQeBm5c (Python)
文章代碼(AID): #1RQeBm5c (Python)