您的位置:首页 > 编程语言 > Python开发

python-str方法使用

2015-03-25 15:10 337 查看
Authenticator = "JonesJ";
Separator = "*";

#获取字符串度
len(Authenticator);
#顺序查找
Authenticator.find("J"); #注意区分大小写
Authenticator.find("J",0,1);
#逆序查找
Authenticator.rfind("J") #注意区分大小写
Authenticator.rfind("J",0,len(Authenticator));
#字符串开头
Authenticator.startswich("Jo")
Authenticator.startswich("Jo",0,len(Authenticator));
#字符串结尾
Authenticator.endswith("J")
Authenticator.endswith("J",0,len(Authenticator));
#字符串join
result = Separator.join(["a","b","c"]);
#截取字符串
result.split(Separator);
result.split(Separator,2); #截取到第二个
#字符串连接
print Authenticator+Separator;
print "abc" "ccc"; #这样python也会自动连接
print "今天天气%s!" % "很不错";
#字符串对齐
Authenticator.center(50) #间隔50个空格
Authenticator.center(50,'*') #可以携带字符
#右边出现字符
Authenticator.ljust(50)
Authenticator.ljust(50,'*');
#左边出现字符
Authenticator.rjust(50);
Authenticator.rjust(50,'*');

#字符串判断
Authenticator.isalpha(); #判断是不全部字母;
Authenticator.isdigit(); #判断是不全部数字;
Authenticator.islower(); #判断是不是全部小写;
Authenticator.isUpper(); #判断是不是全部大写;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: