In Perl I can do:
my ($x, $y) = split /:/, $str;
And it will work whether or not the string contains the pattern.
In Python, howeve
split will always return a list. a, b = ... will always expect list length to be two. You can use something like l = string.split(':'); a = l[0]; ....
split
a, b = ...
l = string.split(':'); a = l[0]; ...
Here is a one liner: a, b = (string.split(':') + [None]*2)[:2]
a, b = (string.split(':') + [None]*2)[:2]