Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement
#4
No, because the values they refer to can be treated as True (non-zero ints, non-empty strings) or False. Further, collections like lists and dictionaries can also be treated like that. Given a list called values, say, the idiomatic way to test that it's non-empty is to write

if values:
    ...
rather than

if len(values) > 0:
    ...
for example.

Also, your variable names are quite meaningless. Try to use names that are descriptive, because they help people (you included!) to read and understand the code.
Reply


Messages In This Thread
If statement - by el_bueno - Feb-01-2020, 05:59 PM
RE: If statement - by ibreeden - Feb-01-2020, 06:05 PM
RE: If statement - by el_bueno - Feb-01-2020, 07:00 PM
RE: If statement - by el_bueno - Feb-01-2020, 08:25 PM
RE: If statement - by ndc85430 - Feb-01-2020, 07:09 PM
RE: If statement - by el_bueno - Feb-01-2020, 07:24 PM
RE: If statement - by ndc85430 - Feb-01-2020, 07:31 PM
RE: If statement - by ibreeden - Feb-02-2020, 10:04 AM
RE: If statement - by el_bueno - Feb-03-2020, 01:43 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020