1

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 '')

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.