Last active
June 11, 2020 07:45
-
-
Save mildcore/5c3d65acc87f6badc6f29863684e61b8 to your computer and use it in GitHub Desktop.
pythonic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
oneline if-else could be replaced by and/or | |
1. a if a else b -> a or b | |
2. f if a else g -> a and f or g # tricky though, so don't use, coz f must be true-like value. | |
""" | |
def f(): | |
return 'f()' | |
def g(): | |
return 'g()' | |
if __name__ == '__main__': | |
print('f if a else g -> a and f or g') | |
for a in (1, 0): | |
print(f'a={a}, {a and f() or g()}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment