首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python 中怎么写if

2012-02-14 
Python 中如何写ifpythoncontentstr.find(ok)&&contentstr.find(not ok)这样表示 在内容中找到 ok或

Python 中如何写if
python 

content=str.find('ok') && content=str.find('not ok')

这样表示 在内容中找到 ok 或者 找到 not ok 对吗?

[解决办法]
并列条件用 and 而不是&&
或者条件用 or 而不是|| 

你的意思应该是or 你是都错了
[解决办法]
if (str.find('ok') != -1 or str.find('not ok') != -1):
print 'find'
[解决办法]
可以 be more pythonic way

>>> s = 'is it ok for ya?'
>>> if 'ok' in s:
... print 'affirmative'
... 
affirmative
>>> 

热点排行