在python中我可以在if语句中使用什么代码来检查字符串,之后我在其上执行.split代码以查看是否只创建了一个字符串?
.split()返回一个列表,你可以调用该len()列表中的函数来获取`.split()'返回的项目数:
>>> s = 'one two three'
>>> s.split()
['one', 'two', 'three']
>>> lst = s.split()
>>> len(lst)
3
Run Code Online (Sandbox Code Playgroud)