亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python cmp import什么模塊?

python cmp import什么模塊?

當年話下 2019-02-05 10:06:05
python cmp import什么模塊
查看完整描述

3 回答

?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

cmp是Python2.x自帶的比較函數,無需import模塊。官方手冊說明:

cmp(x, y)

Compare the two objects x and y and return an integer according to theoutcome.  The return value is negative if x < y, zero if x == y andstrictly positive if x > y.

如下所示:

python3.x則取消了這個函數,以下是官方說明:

The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported. Use __lt__() for sorting, __eq__() with __hash__(), and other rich comparisons as needed. (If you really need the cmp() functionality, you could use the expression (a > b) - (a < b) as the equivalent for cmp(a, b).)大意就是cmp()函數已經“離開”了,如果你真的需要cmp()函數,你可以用表達式(a > b) - (a < b)代替cmp(a,b)


查看完整回答
反對 回復 2019-03-17
?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

比如你一開始用的:
import modulename
如果修改的話,要這樣:
reload(modulename)

查看完整回答
反對 回復 2019-03-17
  • 3 回答
  • 0 關注
  • 807 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號