python字符串处理

 
比较简单了。


# print("hello world范德萨")
# name = "周珂珂"
# v = "周" in name
# if "周" in name:
#     print("ok")
# else:
#     print("error")
#
# print(v)

# a = 123311
# len = a.bit_length()
# print(len)
# name1= "周先生"
# name2="zhouxiansheng"
#数字
#在python3 里面不管数字有多大 都是int类型
#在python2 long
#
# str="123"
# print(type(str))
# a=int(str);
# print(type(a))

# num = "a"
# n =int(num,16)#按照16进制转换成10进制
# print(n)

# test = "abdewrrarr"
# v = test.count("rr",2)
# print(v)



# test = "123456789\tabcdefg"
# test2="username\temail\tpassword\nzhou\tzkk_gzbbxu@163.com\t123\nzhou\tzkk_gzbbxu@163.com\t123\nzhou\tzkk_gzbbxu@163.com\t123"
# v= test2.expandtabs(30)
# print(v)
# test = "a1fdsa范德萨23"
# v= test.isalnum() #是否只包含字母数字
# print(v)

#判断当前是否是数字
# test = "二"
# v1 =test.isdecimal();#false
# v2= test.isdigit();#true
# v3 = test.isnumeric()#true
# print(v1)
# print(v2)
# print(v3)

# test2= "abc放大"
# v = test2.isalpha()
# print(v)

#是否存在不可见的字符\ \t \n
# test = "abc\nt"
# v= test.isprintable()
# print(v)

#首字母大写
# test = "Return True"
# v= test.istitle()
# print(v)


#将字符串中的每一个元素按照指定分隔符拼接
# test ="你是风儿我是沙"
#
# t = ' '
# v= t.join(test)
# print(v)#你 是 风 儿 我 是 沙

#设置宽度,并将内容剧中
# test = "hahha"
# v= test.center(20,"*")
# print(v)#*******hahha********

# test = "aaa"
# v= test.ljust(20,"*")#内容在左边 aaa*****************
# v2= test.zfill(20)#只能000填充 00000000000000000aaa
# print(v,v2)

#去掉 左右空白 包含 \t \n
# test = " adfs "
# test.lstrip()
# test.rstrip()
# test.strip()
# v = test.lstrip("") #去除指定字符串 先进行最多匹配

# 对应关系替换
#
# v = "fdasewrjoijaji,fisaheouqwhr"
# m= str.maketrans("far","123")
# new_v = v.translate(m)
# print(new_v)

# test = "tsest2wsee"
# v = test.partition("se")# 找到第一个分割  ('t', 'se', 'st2wsee') 分割成3份
# print(v)
# v2 = test.rpartition("se")#('tsest2w', 'se', 'e')
# print(v2)
# test.split()
# test.rsplit()


#只能根据换行符  true false 是否保留
# test = "afdas \n fdsa\nfdsa"
# v = test.splitlines(True)#['afdas \n', ' fdsa\n', 'fdsa']
# print(v)

# 切片
# test ="alex"
# v= test[0:1]#0=<  <1 a
# v2= test[0:-1]#0=<  <1 ale
# print(v,v2)
# test = "放大"
#
# v= test.__len__()
# v2 = len(test)
# print(v)



# test = "你好飞洒"
# for item in test:
#     print(item)
#
# index = 0
# while index<len(test):
#     v= test[index]
#     index+=1
#     print(v)
#
# print("end.")



# 帮助创建连续的数字 通过设置步长来指定不连续
v = range(0,100,5)
for item in v:
    print(item)




tempalte = "i am {name},age:{age}"
#v = tempalte.format(name='alex',age=19)
print("............")
v = tempalte.format(**{"name":'alex','age':19}) # **keaygs 这种参数 可以写成name='' 也可以写成字典 
print(v)


bool

None "" () [] {} 0 ==>False 他们都是false



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值