【问题标题】:What is Truthy and Falsy? How is it different from True and False?什么是 Truthy 和 Falsy?它与 True 和 False 有何不同?
【发布时间】:2022-12-04 12:53:35
【问题描述】:

I just learned there are truthy and falsy values in python which are different from the normal True and False.

Can someone please explain in depth what truthy and falsy values are? Where should I use them? What is the difference between truthy and True values and falsy and False values?

  • If bool(value) results in True, then value is truthy.
  • You invented those words yourself, didn\'t you? Anyway, see __nonzero__ and __bool__
  • Truthy/Falsy values are just conveniences for situations where you need a binary test of some kind. It allows for simpler code, and simpler code is often easier to read with less chance for bugs.
  • @zvone Truthy and falsy is used commonly in code golf, if programming languages do not have boolean values.
  • @zvone: \'Truthy\' and \'falsy\' are widely used when comparing programming languages, e.g. PHP vs PERL vs Python vs JS. (Absolutely not just code golf).

标签: python boolean-expression


【解决方案1】:
【解决方案2】:
【解决方案3】:
【解决方案4】:
【解决方案5】:
【解决方案6】:
【解决方案7】:
【解决方案8】:
猜你喜欢
  • 2015-09-18
  • 1970-01-01
  • 1970-01-01
  • 2016-03-27
  • 2018-12-20
  • 2022-07-05
  • 1970-01-01
  • 2021-03-21
  • 1970-01-01
相关资源
最近更新 更多