python输入一个字符,如果是小写字母,转换为其大写形式
时间: 2023-05-26 18:03:15 浏览: 254
如果输入的字符是大写字母或者不是字母,则直接输出原字符。可以使用Python内置函数`islower()`判断是否为小写字母,使用`upper()`方法将其转换为大写形式。
代码如下:
```python
# 输入一个字符
c = input("请输入一个字符:")
# 判断是否为小写字母
if c.islower():
# 转换为大写形式并输出
print(c.upper())
else:
# 输出原字符
print(c)
```
示例输出:
```
请输入一个字符:a
A
请输入一个字符:B
B
请输入一个字符:2
2
```
相关问题
输入一个字符,如果是小写字母,转换为其大写形式,其余字符不变。输入一个字符,如果是小写字母,转换为其大写形式,其余字符不变。
以下是Python代码示例:
```python
ch = input("请输入一个字符:")
if ch.islower():
ch = ch.upper()
print("转换后的字符为:", ch)
```
其中,`islower()`是Python字符串方法,用于判断一个字符是否为小写字母。如果是小写字母,则调用`upper()`方法将其转换为大写字母。最后输出转换后的字符。
python输入一个字符,如果是小写字母,转换为其大写形式,其余字符不变。
```python
char = input("请输入一个字符:")
if char.islower(): # 判断是否为小写字母
char = char.upper() # 转换为大写字母
print(char)
```
注:`islower()`方法用于判断字符串是否全部由小写字母组成。
阅读全文
相关推荐
















