Skip to content

Instantly share code, notes, and snippets.

@mildcore
Last active June 11, 2020 07:45
Show Gist options
  • Save mildcore/5c3d65acc87f6badc6f29863684e61b8 to your computer and use it in GitHub Desktop.
Save mildcore/5c3d65acc87f6badc6f29863684e61b8 to your computer and use it in GitHub Desktop.
pythonic
#!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