Back
Alright, I know how to print variables and strings. But how can I print something like "My string" card.price (it is my variable). I mean, here is my code: print "I have "
(and here I would like to print my variable card.price).
You can do it by your way but you are missing the order that is the only issue:
[unicode(x.strip()) if x is not None else '' for x in row]
Syntax:-
[f(x) if condition else g(x) for x in sequence]
In list comprehension with if condition we can do like as follows:-
[f(x) for x in sequence if condition]
Another way of doing this is:-
def change(f): if f is None: return unicode(f.strip()) else: return '' row = [change(x) for x in row]
def change(f):
if f is None:
return unicode(f.strip())
else:
return ''
row = [change(x) for x in row]
You can also use the following way to solve the problem:-
row = map(change, row)
Be a Python Expert. Enroll in Python Programming Course by Intellipaat
30.9k questions
32.9k answers
500 comments
665 users