Which is the preferred way to concatenate a string in Python?

前端 未结 12 856
眼角桃花
眼角桃花 2020-11-22 06:45

Since Python\'s string can\'t be changed, I was wondering how to concatenate a string more efficiently?

I can write like it:

s += string         


        
12条回答
  •  情话喂你
    2020-11-22 07:13

    In Python >= 3.6, the new f-string is an efficient way to concatenate a string.

    >>> name = 'some_name'
    >>> number = 123
    >>>
    >>> f'Name is {name} and the number is {number}.'
    'Name is some_name and the number is 123.'
    

提交回复
热议问题