码迷,mamicode.com
首页 > 其他好文 > 详细

str字符串 casefold( ) 方法

时间:2018-08-27 23:24:18      阅读:927      评论:0      收藏:0      [点我收藏+]

标签:就是   区别   www   ascii   example   wow   get   汉语   htm   

描述

Python casefold()方法是Python3.3版本之后引入的,其效果和 lower() 方法非常相似,都可以转换字符串中所有大写字符为小写。

两者的区别是:lower() 方法只对ASCII编码,也就是‘A-Z’有效,对于其他语言(非汉语或英文)中把大写转换为小写的情况只能用 casefold() 方法。

语法

casefold()方法语法:

S.casefold()

 

返回值

返回将字符串中所有大写字符转换为小写后生成的字符串。

实例

以下实例展示了casefold()方法的实例:

#!/usr/bin/python3

S1 = "Runoob EXAMPLE....WOW!!!" #英文
S2 = "?"  #德语
 
print( S1.lower() )
print( S1.casefold() )
print( S2.lower() )
print( S2.casefold() ) #德语的"?"正确的小写是"ss"

  

以上实例输出结果如下:

runoob example....wow!!!
runoob example....wow!!!
?
ss

 

str字符串 casefold( ) 方法

标签:就是   区别   www   ascii   example   wow   get   汉语   htm   

原文地址:https://www.cnblogs.com/change06/p/9545314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!