python如何提取字符串?( 二 )


Python中的format()方法可以将变量插入字符串中 。这对于动态生成字符串非常有用 。例如,以下代码使用format()方法创建一个字符串:
```
name = "Python"
version = 3.9
string = "The current version of {0} is {1}".format(name, version)
print(string)
```
输出:
```
The current version of Python is 3.9
```

猜你喜欢