[英]How can I put two strings in one print function?
I want to put two strings and one var in one print function is it possible for example: print('Your Name is' +name 'I like it!')我想在一张打印 function 中放置两个字符串和一个 var 是否有可能,例如: print('Your Name is' +name 'I like it!')
Yes, that is called string concatenation.是的,这称为字符串连接。 You can add combine strings with variables like this:您可以添加带有变量的组合字符串,如下所示:
print("My name is " + first_name + "." + greeting)
Or you could format it like this:或者你可以像这样格式化它:
print(f"My name is {first_name}. {greeting}")
You can use a format string, like so:您可以使用格式字符串,如下所示:
print(f'Your name is {name}. I like it!')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.