python格式化字符串语法_格式化字符串语法

最好是一个format字符串:expr = """if ({0}.autoOverlap == 1){{

{1}.currentTime += 1;

{2}.currentTime += 1;

float $refresh_tx = {3}.translateX;

float $refresh_ty = {3}.translateY;

float $refresh_tz = {3}.translateZ;

float $refresh_rx = {3}.rotateX;

float $refresh_ry = {3}.rotateY;

float $refresh_rz = {3}.rotateZ;

}}else if({0}.autoOverlap == 0){{"

{1}.currentTime = 1;

{2}.currentTime = 1;

}}""".format(firstControl.getName(), hairSyst, nucleus, cube)

注意使用"""三重引号而不是"单引号来格式化多行字符串。在

编辑:

如果原始字符串包含{ },我们必须按照documentation对它们进行转义:6.1.3. Format String Syntax

The str.format() method and the Formatter class share the same syntax

for format strings (although in the case of Formatter, subclasses can

define their own format string syntax).

Format strings contain “replacement fields” surrounded by curly braces

{}. Anything that is not contained in braces is considered literal

text, which is copied unchanged to the output. If you need to include

a brace character in the literal text, it can be escaped by doubling:

{{ and }}.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值