>>> oranges = "10 100 200"
>>> oranges == "10 100 200"
False
>>> apples = "10 20 30"
>>> apples == "10 20 30"
True
Run Code Online (Sandbox Code Playgroud)
"10 100 200"在我的情况下,期望橙子的输出是真的.
我正在寻找是否按顺序存在10 100 200.我尝试了条带化,但它只会启动字符串和字符串的结尾.
DYZ*_*DYZ 10
你应该拆分而不是剥离:
oranges1 = "10 100 200"
oranges2 = "10 100 200"
oranges1.split() == oranges2.split()
#True
Run Code Online (Sandbox Code Playgroud)
在空格上拆分字符串,并与您期望的值列表进行比较:
oranges = '10 100 200'
oranges.split() == ['10', '100', '200']
>>> True
Run Code Online (Sandbox Code Playgroud)
字符串方法的文档在split()这里:https://docs.python.org/3.6/library/stdtypes.html#str.split
您的问题涉及Python 2.此解决方案也适用于您.