为语句设定默认对象。
with (object)
statements
参数
object
新的默认对象。
statements
一个或多个语句,object 是该语句的默认对象。
说明
with 语句通常用来缩短特定情形下必须写的代码量。在下面的例子中,请注意 math 的重复使用:
x = math.cos(3 * math.pi) + math.sin(math.ln10) y = math.tan(14 * math.e)当使用 with 语句时,代码变得更短且更易读:
with (math){ x = cos(3 * pi) + sin (ln10) y = tan(14 * e)}要求
版本 1
请参阅
this 语句
闽公网安备 35060202000074号