python 没有类似 substr() 或 subString() 的方法。不过可以用 string[ indexA: indexB ] 来截取字符串。
str = "this is a string example";
print( str.startswith( 'this' ) );
print( str.endswith( 'example' ) );
print( str.find( 'string' ) );
print( str[ 0: 4 ] ); # 截取 第 0 位到第 4 位的字符,打印 this
print( str[ str.find( 'string' ): str.find( 'string' ) + 3 ] ); # 截取字符串,打印 str
本文介绍了Python中字符串的基本操作,包括如何使用startswith(), endswith(), find()等方法进行字符串的匹配和查找,以及如何通过切片截取特定部分的字符串。通过实例演示了这些功能的具体应用。
286

被折叠的 条评论
为什么被折叠?



