[英]visual studio issue syntax error with combining string to number
currently having some issues with visual code that dont make sense.目前在视觉代码方面存在一些没有意义的问题。 tried printing out the following sentence in python:
尝试在python中打印出以下句子:
count = 0
message = f"We have {count} even numbers."
print(message)
With the following error:出现以下错误:
message = f"We have {count} even numbers."
^
invalid syntax
I'm just wondering what the correct would be, do i need to add a + around the count like java?我只是想知道正确的是什么,我是否需要像java一样在计数周围添加一个+?
It's probably because you're using a version that is under 3.6, if so, use %s
string formatting:可能是因为您使用的版本低于 3.6,如果是这样,请使用
%s
字符串格式:
count = 0
message = "We have %s even numbers." % count
print(message)
Or use str.format
:或使用
str.format
:
count = 0
message = "We have {} even numbers.".format(count)
print(message)
It works even for pyhton 3.5 or less它甚至适用于 pyhton 3.5 或更低版本
num = 10
string_data = "you have {} apples.".format(num)
print(string_data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.