1. 一般的な操作
文字列
'lstr = 'welcome to Beijing Museumitcpps fdsfs'
を例として取り上げます。 キャラクターに対する一般的な操作を紹介します。
find
str が lstr に含まれているかどうかを確認し、含まれている場合は開始インデックス値を返し、そうでない場合は -1 を返します。 。
文法:
lstr.find(str, start=0, end=len(lstr))
例:
lstr = 'welcome to Beijing Museumitcpps fdsfs' print(lstr.find("Museum")) print(lstr.find("dada"))
操作結果:
index
find() メソッドと同じですが、str が lstr にない場合は例外が報告されます。 ############文法:###### 例: 运行结果: 返回 str在start和end之间 在 lstr里面出现的次数 语法: 例: 运行结果: 把 lstr 中的 str1 替换成 str2,如果 count 指定,则替换不超过 count 次. 例: 运行结果: 以 str 为分隔符切片 lstr,如果 maxsplit有指定值,则仅分隔 maxsplit 个子字符串 例: 运行结果: 把字符串的第一个字符大写。 例: 运行结果: 把字符串的每个单词首字母大写。 检查字符串是否是以 obj 开头, 是则返回 True,否则返回 False 例: 运行结果: 检查字符串是否以obj结束,如果是返回True,否则返回 False. 例: 运行结果: 转换 lstr 中所有大写字符为小写 例: 运行结果: 转换 lstr 中的小写字母为大写 例: 运行结果: 删除lstr字符串两端的空白字符。 类似于 find()函数,不过是从右边开始查找。 例: 运行结果: 类似于 index(),不过是从右边开始。 例: 运行结果: 把lstr以str分割成三部分,str前,str和str后。 例: 运行结果: mystr 中每个字符后面插入str,构造出一个新的字符串。 本文详细的讲解了Python基础 ( 字符串 )。介绍了有关字符串,切片的操作。下标索引。以及在实际操作中会遇到的问题,提供了解决方案。希望可以帮助你更好的学习Python。lstr.index(str, start=0, end=len(lstr))
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.index("dada"))
count
lstr.count(str, start=0, end=len(lstr))
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.count("s"))
replace
1str.replace(str1, str2, 1str.count(str1))
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.replace("s", "ttennd"))
split
1str.split(str=" ", 2)
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.split("to", 5))
capitalize
lstr.capitalize()
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.capitalize())
title
>>> a = "hello itcast"
>>> a.title()
'Hello Itcast' #运行结果
startswith
1str.startswith(obj)
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.startswith('we'))
endswith
1str.endswith(obj)
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.endswith('hfs'))
lower
1str.lower()
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.lower())
upper
1str.upper()
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.upper())
strip
>>> a = "\n\t itcast \t\n"
>>> a.strip()
'itcast' #运行结果
rfind
1str.rfind(str, start=0,end=len(1str) )
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.rfind('eijing'))
rindex
1str.rindex( str, start=0,end=len(1str))
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.rindex('eijing'))
partition
1str.partition(str)
lstr = 'welcome to Beijing Museumitcpps fdsfs'
print(lstr.partition('eijing'))
join
lstr = 'welcome to Beijing Museumitcpps fdsfs'
str='233'
lstr.join(str)
li=["my","name","is","LY"]
print(str.join(li))
运行结果:
二、总结
以上がPython 文字列に対する 16 の一般的な操作メソッドの一覧の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

slicingapythonlistisdoneusingtheyntaxlist [start:stop:step] .hore'showitworks:1)startisthe indexofthefirstelementtoinclude.2)spotisthe indexofthefirmenttoeexclude.3)staptistheincrementbetbetinelements

numpyallows forvariousoperationsonarrays:1)basicarithmeticlikeaddition、減算、乗算、および分割; 2)AdvancedperationssuchasmatrixMultiplication;

Arraysinpython、特にnumpyandpandas、aresentialfordataanalysis、offeringspeedandeficiency.1)numpyarraysenable numpyarraysenable handling forlaredatasents andcomplexoperationslikemoverages.2)Pandasextendsnumpy'scapabivitieswithdataframesfortruc

listsandnumpyarraysinpythonhavedifferentmemoryfootprints:listsaremoreflexiblellessmemory-efficient、whileenumpyarraysaraysareoptimizedfornumericaldata.1)listsstorereferencesto objects、with whowedaround64byteson64-bitedatigu

toensurepythonscriptsbehaveCorrectlyAcrossDevelosment、staging、and Production、usetheseStrategies:1)環境variablesforsimplestetings、2)configurationfilesforcomplexsetups、and3)dynamicloadingforadaptability.eachtododododododofersuniquebentandrequiresca

Pythonリストスライスの基本的な構文はリストです[start:stop:step]。 1.STARTは最初の要素インデックス、2。ストップは除外された最初の要素インデックスであり、3.ステップは要素間のステップサイズを決定します。スライスは、データを抽出するためだけでなく、リストを変更および反転させるためにも使用されます。

ListSoutPerformArraysIn:1)ダイナミシジョンアンドフレーケンティオン/削除、2)ストーリングヘテロゼンダタ、および3)メモリ効率の装飾、ButmayhaveslightPerformancostsinceNASOPERATIONS。

toconvertapythonarraytoalist、usetheList()constructororageneratorexpression.1)importhearraymoduleandcreateanarray.2)useList(arr)または[xforxinarr] toconvertoalistは、largedatatessを変えることを伴うものです。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

SublimeText3 中国語版
中国語版、とても使いやすい

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

ホットトピック









