0 votes
1 view
in Python by (47.8k points)
edited by

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).

1 Answer

0 votes
by (107k points)
  • 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]

  • You can also use the following way to solve the problem:-

row = map(change, row)

Related questions

0 votes
2 answers
asked Sep 12, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...