数値型 - 組み込み型 — Python 3.x ドキュメント
bool ブーリアン型 - 組み込み型 — Python 3.x ドキュメント
| 演算 | 結果 |
|---|---|
| x in s | |
| x not in s | |
| s[i] | sの、i番目の要素 (0を起点) |
| s[i:j] | sの、iからjまでのスライス |
| s[i:j:k] | sの、iからjまでの、k毎のスライス |
| s.count(x) | sの中でxが出現する総数 |
| メソッド | 機能 |
|---|---|
| str.find(sub[, start[, end]]) | s[start:end]の範囲で、部分文字列subが含まれている最小のインデックス。位置に無関心ならば、in演算子で調べる |
| str.startswith(prefix[, start[, end]]) | prefixで始まるならTrue |
| str.endswith(suffix[, start[, end]]) | suffixで終わるならTrue |
>>> "abcabc".find("bc")
1
>>> "abcabc".find("bc",2)
4
>>> "abcabc".find("BC")
-1
>>> ",".join(["a","b"]) 'a,b'
[解決!Python]リスト(配列)の要素を文字列のjoinメソッドで結合するには:解決!Python - @IT かわさきしんじ (2023/10/04)
文字列は、スライスで抽出できます。[解決!Python]文字列から特定の文字列以降や特定の文字列の前などを抽出するには(str.find/str.split/str.partitionメソッド、正規表現):解決!Python - @IT かわさきしんじ (2023/10/04)
>>> "abcde"[1:3] 'bc' >>> "abcde"[2:] 'cde' >>> "abcde"[:2] 'ab'