如果没有,最好的方法是什么?
现在我正在做(对于一个 django 项目):
if not 'thing_for_purpose' in request.session:
request.session['thing_for_purpose'] = 5
但它很尴尬。在 Ruby 中是:
request.session['thing_for_purpose'] ||= 5
这样更好。
最佳答案
关于python - Python 是否有像 Ruby 中的 ||= 这样的 "or equals"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3929433/