data = self.cmd("r.out.gdal in=rdata out=geo{0}.tif".format(i))
self.dataOutTIF.setValue("geo{0}.tif".format(i))
str.format(*args, **kwargs)
Perform a string formatting operation. The string on which this
method is called can contain literal
text or replacement fields delimited
by braces {}. Each replacement field
contains either the numeric index of a
positional argument, or the name of a
keyword argument. Returns a copy of
the string where each replacement
field is replaced with the string
value of the corresponding argument.
>>> "The sum of 1 + 2 is {0}".format(1+2)
'The sum of 1 + 2 is 3'
See Format String Syntax for a description of the various formatting
options that can be specified in
format strings.
This method of string formatting is the new standard in Python 3.0, and
should be preferred to the %
formatting described in String
Formatting Operations in new code.
可以使用运算符
%
将字符串注入字符串:这将提供:
您还可以使用
%d
进行整数运算:使用
注意
var
必须是一个字符串,如果不是,则使用var = str(var)
将其转换为一个字符串。例如
这个解决方案最容易阅读/理解,因此对初学者来说更好,因为它只是简单的字符串连接。
相关问题 更多 >
编程相关推荐