C++及python取子串的区别

C++可用substr取子串:

例如:

string s="dlkjsldfjlsfjslfdjk";
string st=s.substr(4,5);

4表示从索引为4的字符开始,5表示子串的个数

s索引为4的字符是's',因此st="sldfj"

python:

st=s[4:9]

从索引为4的字符到索引为9的字符,不包括9

结果如下:

猜你喜欢

转载自blog.csdn.net/qq_27060423/article/details/84651675
今日推荐