Re: [問卦] C程式大神們請進

作者: Roger0123 (Roger)   2017-08-29 04:20:42
※ 引述《ptt0720 (濕濕)》之銘言:
: ##
: string = input()
: ansStr =''
: for i in string:
: ansStr += i.upper() if 'a'<=i<='z' else i.lower()
: print(ansStr)
: ##
Python 的話
用 list comprehension 可以一行解決
print(''.join(c.upper() if c.islower() else c.lower() for c in input()))
感謝鄉民提醒,因為中文字不到30,所以補個測試結果吧:
>>> print(''.join(c.upper() if c.islower() else c.lower() for c in input()))
Test因為中文字不夠30只好補個測試結果
tEST因為中文字不夠30只好補個測試結果
>>>
作者: tony84590 (貓咪起飛)   2017-08-29 04:21:00
幹幹幹,你們到底在講什麼
作者: formatted (ゴミ丼 わがんりんにゃれ)   2017-08-29 04:21:00
Excellent
作者: gigi030507 (火頁火頁)   2017-08-29 04:21:00
Bravo
作者: steve1012 (steve)   2017-08-29 04:23:00
這種簡單的就不用回文惹啦....
作者: SoLaYo (唏噓)   2017-08-29 04:25:00
補字 未滿30繁體中文字你會被桶
作者: ptt0720 (濕濕)   2017-08-29 04:25:00
有c.islower()這個函式哦~猛!! 一行
作者: wasijohn (咖咩哈咩哈)   2017-08-29 04:25:00
說真的 會被水桶ㄅ
作者: q14721472 (精選魚油)   2017-08-29 04:28:00
真的耶 字數不足
作者: formatted (ゴミ丼 わがんりんにゃれ)   2017-08-29 04:34:00
Done
作者: papple23g (逆道者)   2017-08-29 06:32:00

Links booklink

Contact Us: admin [ a t ] ucptt.com