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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -