楼主:
ycl94 (Orz)
2017-08-29 04:43:07※ 引述《Roger0123 (Roger)》之铭言:
: ※ 引述《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,所以补个测试结果吧:
: Test因为中文字不够30只好补个测试结果
: tEST因为中文字不够30只好补个测试结果
如果Python可以参战,那用string函数: swapcase()即可.
ycl94 @ MBA [:][~] python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> raw_input().swapcase()
pTt teStIng
'PtT TEsTiNG'
为了满足30个字的需求, 耍废说明一下 swapcase()就如同这函数名称,
就是将大小写交换(swap), 所以小写就变大写, 反之亦然 :P
作者:
HowLeeHi (处处留心皆正妹)
2017-08-29 04:57:00从C到C++、java、python..等一下Obj-C,C#要出来了吗julia,golang,rust,swift,perl,php,ruby,js,kotlin,asm