If else based on existence of python function optional arguments

arguments, python

Solution

You can simply use `if b:` - this will require the value to be both not `None` and not an empty string/list/whatever.

Problem

I have written a function as follows, with optional argument 'b'. url depends on the existence of b. ``` def something(a, b=None) if len(b) >= 1: url = 'http://www.xyz.com/%sand%s' % (a, b) else: url = 'http://www.xyz.com/%s' (a) ``` This raises an error when `b=None`, saying "object of type 'none-type' has no length" Any ideas how to get around this?

Original source