简体   繁体   English

python中的“ ++”是什么意思?

[英]What does '+ +' mean in python?

I'm reading a python book. 我正在读一本Python书。 It's explaining for loops and range() function. 它解释了循环和range()函数。

But I don't understand what does '+ and +' mean. 但是我不明白“ +”和“ +”是什么意思。


for i in range(7):
    print('hello('+str(i)+')')

Actually it should read as: 实际上,它应为:

string_a + string_b + string_c

It is not about "+ xxx +". 它与“ + xxx +”无关。

It literally concatenate string_a, string_b and string_c together albeit it is not pythonic. 它实际上将string_a,string_b和string_c连接在一起,尽管它不是pythonic。

A more pythonic way may be: 更加Python化的方式可能是:

print( "hello({my_var})".format(my_var=i) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM