mysql - Python 3.X reading null values from a table -
let's assume have resultset couple of fields. 1 of these fields coming 'null' or in python language none. need create method replace whole nones in field specific word example 'unknown'. here method.
def definegender(x): if x not none: return x else: x = 'unknown' return x
now testing
z= none definegender(z) print('{}'.format(z))
unfortunately, approach not work, please can guys let me know best way create validation.
what aim assign reference. languages c, c++ , c# possible. in java , python not. can alter state (if instance pass list, can update elements, cannot set list it).
you can use assignment operator:
z = none z = definegender(z) print('{}'.format(z))
furthermore can make code shorter using ternary operator in definegender
function:
def definegender(x): return x if x not none else 'unknown'
Comments
Post a Comment