鱼C论坛

 找回密码
 立即注册
查看: 951|回复: 2

return是不是自带判断成立则返回true否则返回false

[复制链接]
发表于 2018-6-7 22:28:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. class word(str):
  2.     def __new__(cls,x):
  3.         x = x.split()[0]
  4.         return str.__new__(cls,x)
  5.     def __lt__(self,other):
  6.         return len(self) < len(other)

  7.     def __le__(self,other):
  8.         return len(self) <= len(other)

  9.     def __eq__(self,other):
  10.         return len(self) == len(other)

  11.     def __ne__(self,other):
  12.         return len(self) != len(other)

  13.     def __gt__(self,other):
  14.         return len(self) > len(other)

  15.     def __ge__(self,other):
  16.         return len(self) >= len(other)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-7 22:49:03 | 显示全部楼层
不是return自带,而是写关系表达式的结果就是True或者False
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-6-8 10:37:20 | 显示全部楼层
新人,我的理解同2楼,return只是单纯的执行返回操作,至于是True还是False,是解释器对关系表达式判断的结果
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-20 06:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表