string - In Python, can you have variables within triple quotes? If so, how? -
this simple question some, has me stumped. can use variables within python's triple-quotes?
in following example, how use variables in text:
wash_clothes = 'tuesdays' clean_dishes = 'never' mystring =""" wash clothes on %wash_clothes clean dishes %clean_dishes """ print(mystring)
i result in:
wash clothes on tuesdays clean dishes never
if not best way handle large chunks of text need couple variables, , there ton of text , special characters?
one of ways :
>>> mystring =""" wash clothes on %s ... clean dishes %s ... """ >>> wash_clothes = 'tuesdays' >>> clean_dishes = 'never' >>> >>> print mystring % (wash_clothes, clean_dishes) wash clothes on tuesdays clean dishes never
also @ string formatting
Comments
Post a Comment