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(); #判断是不是全部大写;
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(); #判断是不是全部大写;
相关文章推荐
- python:使用静态方法,__str__函数
- Python3基础 __str__ print一个类的实例对象的时候 使用的魔法方法
- 关于python -os.mkdir(str)方法的使用记录
- Python字符串str的方法使用
- python中_str_使用方法
- Python--str与repr以及eval的使用方法
- Python使用re实现str.strip()方法,去除首尾的空格
- python的str,unicode对象的encode和decode方法
- Python httplib,smtplib使用方法
- Python __getattr__与__setattr__使用方法
- 使用python获取本地时区的几种方法
- python中datetime的比较方法使用
- python 的方法不能使用中文
- 【用Python写爬虫】获取html的方法【一】:使用urllib
- 【原】Python/C API使用方法简介 (在C/C++中嵌入Python)
- Python中使用中文的方法
- python的str,unicode对象的encode和decode方法(转)
- Python strip lstrip rstrip使用方法
- Python strip lstrip rstrip使用方法(字符串处理空格)
- p4.pm p4python p4perl p4api 的使用方法