python02 基本数据类型 string

#python 字符串
#/user/sbin/py python
# -*-coding:utf-8-*-
test1 = "abc\tfafa"
ag1 = test1.expandtabs(10)#遇到制表符(和开头以前)补全十个占位
print(ag1)
test2 = "abc123"
result1 = test2.isalnum() #判断字符串是否只包含字母和数字
print(result1)
result2 = test2.isalpha() #判断字符串是否只包含字母和汉字
print(result2)
test3 = "1234"
result3 = test3.isdecimal()
result4 = test3.isdigit() #两个都可以用于判断字符串中是否只包含数字,但isdigit更宽泛一些,可以包含一些数字编号

test4 ="②③"
result5 = test4.isdigit()
result6 = test4.isdecimal()

tes41 = "Ⅱ"
r5 = tes41.isnumeric() # 比isdigit更加宽泛,可以包含汉字,和罗马数字

print(result3,result4,result5,result6,r5)
test5 = "AleDFAF"
v = test5.swapcase() #大小写转换,大写变小写,小写变大写
v2 = test5.lower() #转换成小写
v3 = test5.upper() #转换成大写
print(v,v2,v3)

test6 = "abcd\tdef"
result7 = test6.isprintable() #判断字符串打印输出效果和程序中看到的字符串是否一致
print(result7)
test7 = "    "
result8=test7.isspace() #判断是否全部为空格
print(result8)

test8 = "my favorite goods "
v1 = test8.istitle() #该方法只对英文使用,判断该行是否为标题
print(v1)
v2 = test8.title()  #将一行转换为标题
print(v2)
test9 = "我和我的祖国"
vv = "__".join(test9) #插入字符
print(vv)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值