可以使用Python中的字符串格式化来实现。具体方法是使用占位符(%)来代替变量,并在字符串的最后面使用%操作符来引用变量。以下是示例代码:
name = 'John'
age = 25
result = "My name is %s and I'm %d years old" % (name, age)
print(result)
运行上述代码将返回以下字符串:
My name is John and I'm 25 years old
在上面的代码中,%s表示字符串类型变量,%d表示整型变量。注意,在字符串中使用这些占位符时,应该使用括号将变量包围起来,并且在字符串的最后使用%操作符来引用这些变量。