字母大小写怎么在python3中用代码表示
这篇文章给大家分享的是有关字母大小写怎么在python3中用代码表示的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
具体的代码示例如下:
首字母小写
如下方法将令给定字符串的第一个字符统一为小写。
def decapitalize(string): return str[:1].lower() + str[1:] decapitalize('FooBar') # 'fooBar' decapitalize('FooBar') # 'fooBar'
大写第一个字母
以下代码块会使用 title() 方法,从而大写字符串中每一个单词的首字母。
s = "programming is awesome" print(s.title()) # Programming Is Awesome
由大小写字母组成的字符串,请对它进行重新组合
def ReverseArray(ch): lens=len(ch) begin=0 end=lens-1 while begin<end: while ch[begin]>='a' and ch[end]<='z' and end>begin: begin+=1 while ch[begin]>='A' and ch[end]<='Z' and end>begin: end-=1 ch[begin],ch[end]=ch[end],ch[begin] if __name__=='__main__': ch=list('AbcDef') ReverseArray(ch) i=0 while i<len(ch): print(ch[i]) i+=1 输出: f b c e D A
感谢各位的阅读!关于字母大小写怎么在python3中用代码表示就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!