python里面什么情况下需要加引号?

例如:

        a = 5

        print("hello world",a)

        输出的不就是

      >>>hello world 5

  为什么后面的不用加“”呢?还有这样的话,和print(“{0}{1}”.format(“hello world”,5)的区别是啥

后面的不用加""是因为a是一个变量,而不是字符串

print("hello world",a)

把hello world 和变量a连接在一起,中间用print的sep参数连接(sep的默认值是" ")

print("{0}{1}".format(“hello world”,5))

把hello world 和变量a连接在一起("hello world"是第"零"个参数,变量a是第"一"个,直接连接)

如果是print("{0}{1}{0}".format(“hello world”,5))结果则为hello world5hello world