2010-11-24 89 views
7

我只是碰到這種here來了,總是像這樣使用:<>運算符在python中做什麼?

if string1.find(string2) <> -1: 
    pass 

什麼是<>運營商做的,爲什麼不使用通常的==in

很抱歉,如果以前回答過,搜索引擎不喜歡標點符號。

+1

像這樣的網站應該有一個正則表達式的搜索引擎。像谷歌代碼搜索一樣。 – 2010-11-24 01:19:49

+0

[Python(或一般編程))的可能重複。爲什麼用<>代替!=並且存在風險?](http://stackoverflow.com/questions/2312169/python-or-general-programming-why-use-instead-of-and-are-there-risks ) – 2014-04-23 21:18:12

回答

7

<>!=相同,但the <> form is deprecated。您的代碼示例可以更清晰地寫爲:

if string2 not in string1: 
    pass 
+1

`string1中沒有string2`會更好`string2不在string1中' – 2010-11-24 01:18:07

+0

@Chris真,已更新答案 – fmark 2010-11-24 01:18:52

0

<>意味着大於或小於,基本上'不等於'。