Python Alpha 101 B: Strings
Python Alpha 101 B: Strings
Strings
AL NAFI,
A company with a focus on education,
wellbeing and renewable energy.
However you will also find yourself inserting integers and floats into
strings quite often as well. There are two different ways to accomplish
this task. We'll start with the old way of doing things and then move on
to the new.
my_string
This probably looks pretty weird, but basically we just changed our %s into
%(lang)s, which is basically the %s with a variable inside it. The second part is
actually called a Python dictionary that we will be studying in the next class.
Basically it's a key:value pair, so when Python sees the key "lang" in the
string AND in the key of the dictionary that is passed in, it replaces that key
with its value.
© 2018 Al-Nafi. All Rights Reserved. 13
More Examples with text
print("%(value)s %(value)s %(value)s !" % {"value":"Sharfoo"})