Formatted String Literals in Python 2 -
while writing module in python 2.7 had need of way doing
name = "rodrigo" age = 34 print f"hello {name}, age {age}".format()
although know do:
print "hello {name}, age {age}".format(name=name, age=age)
format()
in scope variables name
, age
, cast them string (if possible) , paste message. i've found implemented in python 3.6+, called formatted string literals. so, wondering (couldn't find googling) if has made approach similar python 2.7
you can try hackish way of doing things combining builtin locals
function , format
method on string:
foo = "asd" bar = "ghi" print("{foo} , {bar}".format(**locals())
Comments
Post a Comment