为什么每个字符串上都有空字符串? [英] Why empty string is on every string?

查看:83
本文介绍了为什么每个字符串上都有空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

<预><代码>>>>s = '蟒蛇'>>>s.index('')0>>>s.index('p')0

解决方案

这是因为'python'中从索引0开始的长度为0的子串等于空串:

<预><代码>>>>s[0:0]''

当然每个长度为零的任何字符串的子字符串都等于空字符串.

For example:

>>> s = 'python'
>>> s.index('')
0
>>> s.index('p')
0

解决方案

This is because the substring of length 0 starting at index 0 in 'python' is equal to the empty string:

>>> s[0:0]
''

Of course every substring of length zero of any string is equal to the empty string.

这篇关于为什么每个字符串上都有空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆