P11 Custom string formatting
format strings——there are multiple ways that you can do the exact same types of string concatenation.
P12实操
first_name='liu'
last_name='ding yun'
output='hello ' + first_name + ' ' + last_name
output='hello,{}{}'.format(first_name,last_name)
output='hello,{0}{1}'.format(first_name,last_name)
output=f'hello,{first_name} {last_name}'
output='hello,%s %s'%(first_name,last_name)
print(output)
i really like that last string format with the little f at the very beginning there.⬇️ you'll also notice that there's a lot of other programming languages that have a very similar construct. I also really like the fact that it is self-documenting, because i can very clearly see......
first_name='liu'
last_name='ding yun'
# output='hello ' + first_name + ' ' + last_name
# output='hello,{}{}'.format(first_name,last_name)
# output='hello,{0}{1}'.format(first_name,last_name)
output=f'hello,{first_name} {last_name}'
# output='hello,%s %s'%(first_name,last_name)
print(output)



