OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Rewrite the idiom "... if foo is not None else None"

  • Thread starter Thread starter Basj
  • Start date Start date
B

Basj

Guest
Is there a way, for example with boolean logic (or, and, ...) or another way, to replace the idiom:

Code:
... if foo is not None else None

Example: foo = int(foo) if foo is not None else None

by something less redundant? (without any helper function)

Note: not a duplicate of Convert to int if not None, else keep None, this question was not well focused.
<p>Is there a way, for example with boolean logic (or, and, ...) or another way, to replace the idiom:</p>
<pre><code>... if foo is not None else None
</code></pre>
<p>Example: <code>foo = int(foo) if foo is not None else None</code></p>
<p>by something less redundant? (without any helper function)</p>
<p>Note: not a duplicate of <a href="https://stackoverflow.com/questions/78661811/convert-to-int-if-not-none-else-keep-none">Convert to int if not None, else keep None</a>, this question was not well focused.</p>
 

Latest posts

G
Replies
0
Views
1
Gamal Othman
G
Top