Python文字列操作

**Pythonでの文字列の定義:文字列は、Unicodeコードポイントの不変のシーケンスです。 **

Pythonの組み込み関数は、文字列を使用する強力な方法を提供し、一般的なメソッドを習得し、データ処理、インタビュー、および筆記試験に非常に役立ちます。

dir(str)['__add__','__class__','__contains__','__delattr__','__dir__','__doc__','__eq__','__format__','__ge__','__getattribute__','__getitem__','__getnewargs__','__gt__','__hash__','__init__','__init_subclass__','__iter__','__le__','__len__','__lt__','__mod__','__mul__','__ne__','__new__','__reduce__','__reduce_ex__','__repr__','__rmod__','__rmul__','__setattr__','__sizeof__','__str__','__subclasshook__','capitalize','casefold', 'cent
er', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isuppe
r', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfi
ll']

まず、文字列はシーケンスであるため、スライス操作とインデックス作成操作をサポートします。詳細については、この記事 [** Python基本データタイプの詳細な説明**](http://mp.weixin.qq.com/s?__biz=MzI5NzIyMjQwNA==&mid=2247484635&idx=1&sn=284255921f5a64e2dcd95368f0d99686&chksm=ecb92cb0dbcea5a6ad589a87077de3ea3ebb2dcc259fad9b58e5b1d9c52a52430062bf30b4bf&scene=21#wechat_redirect)**を参照してください。 ****

以下は、一般的な組み込み関数の要約です。

s="hello testers !"print(s.replace('hello','hi')) #ハイテスターを出力!

s="hello testers !"print(s.split()) #出力['hello','testers','!']print(s.partition('testers')) #出力('hello ','testers',' !')

s=" hellotesters! "print(s.strip()) #hellotestersを出力する!print(s.rstrip()) #hellotestersを出力する!print(s.lstrip()) #hellotestersを出力する!

s1="hellotesters!"
s2="HELLO TESTERS!"
s3="Hello Testers!"
s4=s1="hello testers!"print(s1.upper()) #HELLOTESTERSを出力します!print(s2.lower()) #helloテスターを出力する!print(s3.swapcase()) #HELLOTESTERSを出力!print(s1.capitalize()) #Helloテスターを出力!print(s4.title()) #Helloテスターを出力!

s1="hello testers!"print(s1.count('l')) #出力2プリント(s1.find('hello')) #出力0print(s1.rfind('testers!')) #出力6

s1="hellotesters!1234567890"
s2="hellotesters"
s3="1234567890"
s4="HELLOTESTERS"print(s1.isalnum()) #Falseを出力
print(s2.isalpha()) #Trueを出力
print(s3.isdigit()) #Trueを出力
print(s4.isupper()) #Trueを出力
print(s2.islower()) #Trueを出力

Recommended Posts

Python文字列操作
Python文字列
Python文字列
PythonのStr文字列
Pythonが文字列の大文字小文字を変換する方法
Pythonインタビューの質問:文字列の連結
Python文字列3形式の出力
Pythonは文字列と数値のスプライシングを実装します
Python文字列プーリングの前提
Pythonの古典的なプログラミングの質問:文字列の置換
Pythonマルチスレッド
Python CookBook
Python FAQ
Python3辞書
Python3モジュール
python(you-get)
Pythonの基本
パスワードの強度を判断するためのPython文字列
Python記述子
Pythonの基本2
Python exec
Pythonノート
Python3タプル
CentOS + Python3.6 +
Python Advanced(1)
Pythonデコレータ
Python IO
Pythonマルチスレッド
Pythonツールチェーン
Python3リスト
Pythonマルチタスク-日常
Pythonの概要
pythonの紹介
Pythonアナリティック
Pythonの基本
07.Python3関数
Pythonの基本3
Pythonマルチタスクスレッド
Python関数
python sys.stdout
python演算子
Pythonエントリ-3
Centos 7.5 python3.6
pythonキューキュー
Pythonの基本4
Pythonの基本5