如何将字符串更改为大写

本文翻译自:How to change a string into uppercase

I have problem in changing a string into uppercase with Python. 我在使用Python将字符串更改为大写时遇到问题。 In my research, I got string.ascii_uppercase but it doesn't work. 在我的研究中,我得到了string.ascii_uppercase但它不起作用。

The following code: 以下代码:

 >>s = 'sdsd'
 >>s.ascii_uppercase

Gives this error message: 给出此错误消息:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'str' object has no attribute 'ascii_uppercase'

My question is: how can I convert a string into uppercase in Python? 我的问题是: 如何在Python中将字符串转换为大写?


#1楼

参考:https://stackoom.com/question/cqBy/如何将字符串更改为大写


#2楼

s = 'sdsd'
print (s.upper())
upper = raw_input('type in something lowercase.')
lower = raw_input('type in the same thing caps lock.')
print upper.upper()
print lower.lower()

#3楼

to make the string upper case -- just simply type 使字符串大写 - 只需键入

s.upper()

simple and easy! 简单易行! you can do the same to make it lower too 你也可以做同样的事情来降低它

s.lower()

etc. 等等


#4楼

for making uppercase from lowercase to upper just use 用于从小写到大写的大写字母

"string".upper()

where "string" is your string that you want to convert uppercase 其中"string"是您要转换为大写的字符串

for this question concern it will like this: 对于这个问题关注它会是这样的:

s.upper()

for making lowercase from uppercase string just use 从大写字符串制作小写只是使用

"string".lower()

where "string" is your string that you want to convert lowercase 其中"string"是您要转换为小写的字符串

for this question concern it will like this: 对于这个问题关注它会是这样的:

s.lower()

If you want to make your whole string variable use 如果你想让你的整个字符串变量使用

s="sadf"
# sadf

s=s.upper()
# SADF

#5楼

For questions on simple string manipulation the dir built-in function comes in handy. 对于简单字符串操作的问题, dir内置函数派上用场。 It gives you, among others, a list of methods of the argument, eg, dir(s) returns a list containing upper . 它为您提供了参数方法的列表,例如, dir(s)返回包含upper的列表。


#6楼

>>> s = 'sdsd'
>>> s.upper()
'SDSD'

See String Methods . 请参阅字符串方法

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值