Jul-04-2017, 08:09 PM
Really? When I run:
Please see String Formatting
print ("Its fleece was white as {}.".format(snow))I get:
Error:Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'snow' is not defined
In your first example, the '{}' acts as a place holder for the elements in the '.format()' segment, in this case it is looking for the variable named snow.snow = "snow" print("It's fleece was white as {}".format(snow))
Output:Its fleece was white as snow.
In your second example you are simply printing the string "Its fleece was white as snow."Please see String Formatting
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition