Programing Language/Python
[Python] default value if none
pcm9881
2023. 3. 6. 15:04
방법 1
return x or "default"
방법 2
return "default" if x is None else x
참조
[stakoverflow]: https://stackoverflow.com/questions/13710631/is-there-shorthand-for-returning-a-default-value-if-none-in-python
Is there shorthand for returning a default value if None in Python?
In C#, I can say x ?? "", which will give me x if x is not null, and the empty string if x is null. I've found it useful for working with databases. Is there a way to return a default value if Py...
stackoverflow.com
728x90