function - Python How to use sep=" " only between second and third item -


i have question print function.

print("welcome to", a, "this new world") 

how can use sep=" " full stop between whatever , "this new world", not between "welcome to" , whatever is?

i using python 3.

basically want print this:

assuming a "cake".

welcome cake. new world #              ^ full stop talking about.  

it won't accept question here more detail: have tried google didn't more basic , talking using separation function when there 2 items of text.

there bunch of ways achieve describing better others.

1st way

we can first keep syntax have make slight changes:

print("welcome " + + ". new world")

as may notice, added space after "to" , period , space before "this". replaced commas +

2nd way

we can use %s. converts variable string , allows write whole output without needing use + more pythonic.

print("welcome %s. new world" % a)

3rd way

this way people approach it.

print("welcome {}. new world".format(a))

an ever better version of nosklo mentioned:

print("welcome {name}. new world".format(name=a))


this website may further.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -