Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How can I create a string where the parameters can be none.
def create_string(main_val, test_val=None, test_val2=None) return '%s-some_values: %s/%s/' % (main_val, test_val if test_val else '', testval2 if testval2 else '')
Your code is working, just you messed up the variable name. You defined the variable as test_val2 but you're using it as testval2. Consider using the same name for your variables.
test_val2
testval2
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.