python str字符串

字符串的赋值

a = "hello"
b = 'westos'
c = "what's up"
d = """
用户管理
1.添加用户
2.删除用户
3.显示用户
"""
 

 

# 索引:0,1,2,3,4 索引值是从0开始
s = 'hello'
print s[0]
print s[1]

# 切片
print s[0:3] # 切片的规则:s[start:end:step] 从start开始到end-1结束,步长:step
print s[0:4:2]
# 显示所有字符
print s[:]
# 显示前3个字符
print s[:3]
# 对字符串倒叙输出
print s[::-1]
# 除了第一个字符以外,其他全部显示
print s[1:]

# 重复
print s * 10

# 连接
print 'hello ' + 'world'

# 成员操作符
print 'q' in s       # s字符串中是否含有q
print 'he' in s
print 'aa' in s
 

s = 'hello.jpg'
# 找出字符串是否以XXX结尾
print s.endswith('.png')

url1 = 'http://www.baidu.com'
url2 = 'file:///mnt'

print url1.startswith('http://')  # url1是否以http://开头
print url2.startswith('f')
 

# 判断字符串里面的每个元素是否为什么类型
# 一旦有一个元素不满足,就返回False
print '123'.isdigit()
print '123abc'.isdigit()

# title:标题 判断某个字符串是否为标题(第一个首字母大写,其余字母小写)
print 'Hello'.istitle()
print 'HeLlo'.istitle()

print 'hello'.upper()  # 将某个字符串转化为大写
print 'hello'.islower() # 判断某个字符串是否为小写
print 'HELLO'.lower()  # 将某个字符串转化为小写
print 'HELLO'.isupper() # 判断某个字符串是否为小写
print 'hello'.isalnum()  # 判断某个字符串是否为小写和数字
print '123'.isalpha() # 判断某个字符串是否为字母
print 'qqq'.isalpha() 

s = 'hello world'
#print len(s)

# find找到字符串 并返回最小的索引
print s.find('hello')
print s.find('world')

print s.replace('hello','westos')
 

print 'helloooo'.count('o') 

"""
# split对于字符串进行分离,分割符为'.'
s = '172.25.254.250'
s1 = s.split('.')
print s1

date = '2018-8-27'
date1 = date.split('-')
print date1


# 连接
print ''.join(date1)
print '/'.join(date1)

print '/'.join('hello')
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值