パンダの記録帳

自分が学んだことをこのブログで記録していきます。 今のメインは、"Android studio"、"Python"、"光ファイバ"、”電気”など

Python 文字列

文字列の扱い、一例

 

>>> word = "Python"
>>> word[0]
'P'
>>> word[1]
'y'
>>> word[-1]
'n'
>>> word[0:2]
'Py'
>>> word[2:5]
'tho'
>>> word[:2]
'Py'
>>> word[2:]
'thon'
>>> word[10]
Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    word[10]
IndexError: string index out of range
>>> word[1:10]
'ython'
>>> word[10:]
''