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 Python finds None in a variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use the
oroperator:Note that this also returns
"default"ifxis any falsy value, including an empty list, 0, empty string, or evendatetime.time(0)(midnight).