2-string_working_with_text

正文

字符串中包含引号

  message_double="Dale's world"
  message_slash='dale\'s world'
  message_single='"dale"'
   #"dale"

字符串切片

 print(message_double[0:5])
 print(len(message_double))

字符串函数

  print(message_double.upper())
    # lower, islower...
  print(message_double.count('Dale'))
    # 计算字符串中有多少个被检测字符  out:1
  print(message_double.find('w'))
    # 返回 被检测的字符子串的位置 index     out:7

替换

  message_replace="dale dale dale,hello!"
  print(message_replace.replace('dale',' ',message_replace.count('dale')-1)) # in:原值,替换值,替换的次数
  #     out:dale,hello!

格式字符串

  greeting="hello"
  name='dale'
  age=15
  #方法1 
  print(greeting+', '+ name +'. welcome!')
  #方法2
  print("{}, {}{}.welcome!".format(greeting,name,age))
  #方法3
  print(f'{name.upper()} is a boy')
  
#帮助
print(help(str))

引用

本文主要参考下列视频内容,翻译并亲测代码后形成此文,感谢视频作者的无私奉献!
2-string_working_with_text

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值