美文网首页Python🐍
python - string总结

python - string总结

作者: Pingouin | 来源:发表于2020-10-11 03:44 被阅读0次

Strings

  • Strings are immutable.
  • Strings are sequences.
  • Strings have many methods. See Table 4.2.
  • Standard operations:
    • length function: len(s)
    • membership:in

Indexing and Slicing

Given: s = 'Mississippi'

  • Indexing starts at 0: s[0] is 'M'.
  • Negative indices work backward from the end: s[-1] is 'i'.
  • Slicing selects a subset up to but not including the final index: s[3:6] is 'sis'.
  • Slicing default start is the beginning, so s[:4] is 'Miss'.
  • Slicing default end is the end, so s[7:] is 'ippi'.
  • Using both defaults makes a copy: s[:].
  • Slicing’s optional third argument indicates step: s[:6:2] is 'Msi'.
  • The idiom to reverse a string: s[::-1] is 'ippississiM'

Formatting

{arg:[[fill]align][sign][#][0][minimum width][,][.precision]type}

Iteration: for, enumerate

  • for walks through each character in a string:
for ch in 'Mississippi':
  • enumerate generates both the index and the character:
for index, ch in enumerate('Mississippi'):

相关文章

  • 2017.6.13-14

    学习python总结python常用的方法string的常用方法dictionary的常用方法 python抽象,...

  • python - string总结

    Strings Strings are immutable. Strings are sequences. Str...

  • 字符串处理总结

    str='python String function' 生成字符串变量str='python String fu...

  • python2 string

    python2 string string object and unicode objects = 'abc' ...

  • Python字符串格式化

    python 1.0+ (printf-style-string-formatting) python 2.6+ ...

  • Python 中 is 和== 的区别

    初学python的时候,发现python中== 用来比较两个string的值,之前用java的话,比较string...

  • Python基础教程

    python分类 list int string dict

  • Python String

    string 判断开头if 字符串变量.startswith("条件") 判断结尾if 字符串变量.endswit...

  • Python

    python string strip, removes all whitespace at beginning ...

  • Java String总结

    Java String总结 String 类 String类定代码如下: 从代码看有两点需要注意: String类...

网友评论

    本文标题:python - string总结

    本文链接:https://www.haomeiwen.com/subject/pymspktx.html