Why does Python not have an 'is even' method for integers and what should I do about it? -


There is no 'is_even' method or nothing for integer in Python.

For example:

  if with integer_value%, 2 == 0: do something   

It is not clear what to really do.

While it is more understandable immediately:

  if_even (integer_value): # something   

this means That I need to write an AVIven function where I want it.

  def is_even (integer): if integer% 2 == 0: return true: return wrong   

What is a better option? What is the code itself that is readable and clearly intended, or is there comments everywhere?

To quote a recent blog entry which is rounding:

"Notice how much stronger this approach is compared to using comments, if you have arguments If you change, you put immediate pressure to change the variable name, it is not so with comments. I agree with DHH, the comment is dangerous and is caused by rot - it is better to write self-documentation code. >

Am I this multi

There is usually no problem in local functions - or using lambdas - and I usually do this when they make it more pronounced.

However, the core language of particular functions of this class is generally unnecessary , And to move the path of bloated core down to add to the global / underlying function (or even as a special type of method) Habit: Why not is_prime or is_natural ?

  def do_my_stuff (numbers): def is_even (i): return i % 2 == 0 # Usage is_even, where this return can be referenced above the map (numbers, is_even)    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -