Python编程---字符串中的内嵌函数

                         字符串中的内嵌函数

1、isalpha(判断是否都为字母)

#! /usr/bin/python
#coding:utf-8


string="welcome"
string1="welcome123"

print "string:%d"%(string.isalpha())
print "string1:%d"%(string1.isalpha())

2、strip(字符串分割)

#! /usr/bin/python
#coding:utf-8


string=" welcome to my home  "
string1="what's your name"
string1_strip=string1.strip()
string_strip=string.strip()
print string
print string_strip

print "================"
print string1
print string1_strip

3、split(去除前导和尾随空格)

#! /usr/bin/python
#coding:utf-8


string="welcome to my home"
string_split=string.split(" ")
print string
print string_split

4、join(字符串拼接)

#! /usr/bin/python
#coding:utf-8


string="welcome to my home"
string_split=string.split(" ")
string_join=" ".join(string_split)

print string
print string_split
print string_join

5、__len__(字符串长度)

#! /usr/bin/python
#coding:utf-8
string="welcome to my home"
string_len=len(string)

print string
print string_len

猜你喜欢

转载自blog.csdn.net/yanlaifan/article/details/114992439
今日推荐