op1 if condition else op2
Example
userGender = '0' if userFields[1] == 'M' else '1'
userAge = '0' if userFields[2] == '18-24' else \
'1' if userFields[2] == '25-34' else \
'2' if userFields[2] == '35-49' else '3'
Another interesting way here.
Example
userGender = '0' if userFields[1] == 'M' else '1'
userAge = '0' if userFields[2] == '18-24' else \
'1' if userFields[2] == '25-34' else \
'2' if userFields[2] == '35-49' else '3'
Another interesting way here.