0
Follow
0
View

python Alphabet Conversion(Easy for)

hainancyp 注册会员
2023-02-28 02:09

faint... The string comes with swapcase method to learn about

dkzhu120 注册会员
2023-02-28 02:09
img

< !- - - - - >
deedis 注册会员
2023-02-28 02:09

Method 1: for loop through

content = "heLLo woRlD!"
result = []

for word in content:
    # 判断是小写字母
    if ord(word) in range(97,123):
        result.append(word.upper())
    # 判断是大写字母
    elif ord(word) in range(65,91):
        result.append(word.lower())
    else:
        result.append(word)

print(''.join(result))

Method 2: Call the string built-in method directly

content = "heLLo woRlD!"
print(content.swapcase())

If it helps, please click to accept ~

dutefei 注册会员
2023-02-28 02:09

Please accept, thank you! 1, the effect is as follows

img

# 输入10个字符,字符串只含字母,将字母的大小写转换一下,将转换后的字符串输出
old = input('请输入10个字符:')
newValue=''
for item in old:
    if item.isupper():
        newValue+=item.lower()
    else:
        newValue+=item.upper()
print(f'字母的大小写转换后字符:{newValue}')

About the Author

Question Info

Publish Time
2023-02-28 02:09
Update Time
2023-02-28 02:09