「Python」文字列の途中から最後までを取得する方法

環境
PyCharm 2021.3
Python 3.9.7

書式
文字列[ 開始位置 : ]
最初の1文字目の位置は0です。
区切りのコロンは使用します
引数1の「開始位置」から最後までの文字を返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
str = 'テストデータ123#@'
print('文字列の開始位置を指定して最後まで取得する')
print(str[2:])
print(str[3:])
print(str[4:])
print(str[5:])
# coding: utf-8 str = 'テストデータ123#@' print('文字列の開始位置を指定して最後まで取得する') print(str[2:]) print(str[3:]) print(str[4:]) print(str[5:])
# coding: utf-8

str = 'テストデータ123#@'

print('文字列の開始位置を指定して最後まで取得する')
print(str[2:])
print(str[3:])
print(str[4:])
print(str[5:])

実行結果
文字列の開始位置を指定して最後まで取得する
トデータ123#@
データ123#@
ータ123#@
タ123#@

Python

Posted by arkgame