Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (47.6k 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 (106k points)
edited by
  • 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)

Be a Python Expert. Enroll in Python Programming Course by Intellipaat 

Related questions

0 votes
2 answers
asked Sep 12, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...