17xie > Python 语言参考手册 > 6.4 pass语句 The pass statement
背景:                 
[本书目录] [图书首页] [本书讨论区]  
链接地址:http://www.17xie.com/read-37451.html    注册17xie 一起来写书 实现您的出书梦想!


6.4 pass语句 The pass statement

pass_stmt  ::=  "pass"
Download entire grammar as text.

pass is a null operation -- when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example:

pass 是一个空操作 -- 当执行它, 什么也不做. 它在句法上要求有一个语句时但不需要写代码时用到,例如:

def f(arg): pass    # a function that does nothing (yet)

class C: pass       # a class with no methods (yet)

 


6.5 del 语句 The del statement


del_stmt  ::=  "del" target_list
Download entire grammar as text.

Deletion is recursively defined very similar to the way assignment is defined. Rather that spelling it out in full details, here are some hints.
删除与赋值的定义方法类似, 也是递归的. 下面是一些的说明:
Deletion of a target list recursively deletes each target, from left to right.
一个目标表的递归删除操作会从左到右地删除其中的每个对象地.
Deletion of a name removes the binding of that name from the local or global namespace, depending on whether the name occurs in a global statement in the same code block. If the name is unbound, a NameError exception will be raised.
删除名字就是在局部名字空间和全局名字空间删除掉该名字的绑定(必须存在), 从哪个名字空间删除决定于该名字是否出现在其代码块的globals语句中.
It is illegal to delete a name from the local namespace if it occurs as a free variable in a nested block.
Deletion of attribute references, subscriptions and slicings is passed to the primary object involved; deletion of a slicing is in general equivalent to assignment of an empty slice of the right type (but even this is determined by the sliced object).
对于属性引用, 下标和片断的删除会作用到相关的主元对象, 对片断的删除一般等价于对该片断赋予相应类型的空片断(但这也受被截为片断的对象的限制).



6.6 print语句 The print statement


print_stmt  ::=  "print" ( [expression ("," expression)* [","]]
    | ">>" expression [("," expression)+ [","]] )
Download entire grammar as text.

print evaluates each expression in turn and writes the resulting object to standard output (see below). If an object is not a string, it is first converted to a string using the rules for string conversions. The (resulting or original) string is then written. A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line. This is the case (1) when no characters have yet been written to standard output, (2) when the last character written to standard output is "\n", or (3) when the last write operation on standard output was not a print statement. (In some cases it may be functional to write an empty string to standard output for this reason.) Note: Objects which act like file objects but which are not the built-in file objects often do not properly emulate this aspect of the file object's behavior, so it is best not to rely on this.
print依次对每个表达式求值,然后把结果对象写入标准输出(见下面)。如果一个对象不是一个字符串,首先用字符串转换法则将其转成一个字符串。然后(结果的或者原来的)字符串就被写入。在每个对象被(转换和)写入以前,输出系统会先写一个空格,除非它认为当前处在一行的起首位置。这里是(起首)情形:(1)当尚未有字符写到标准输出,(2)当上一个写入标准输出的字符是"\n",或者(3)当前一次作用于标准输出上的操作不是print语句。注意:那些行为类似file对象但是并非内置file对象的对象常常不能正确地模拟file对象这方面的行为,所以最好不要依赖于此。
A "\n" character is written at the end, unless the print statement ends with a comma. This is the only action if the statement contains just the keyword print.
A "\n" character is written at the end, unless the print statement ends with a comma. This is the only action if the statement contains just the keyword print.
Standard output is defined as the file object named stdout in the built-in module sys. If no such object exists, or if it does not have a write() method, a RuntimeError exception is raised.
标准输出定义为内置模块sys中名为stdout的file文件对象。如果该对象不存在,或者它没有write()方法,会抛出一个RuntimeError异常。
print also has an extendedform, defined by the second portion of the syntax described above. This form is sometimes referred to as ``print chevron.'' In this form, the first expression after the >> must evaluate to a ``file-like'' object, specifically an object that has a write() method as described above. With this extended form, the subsequent expressions are printed to this file object. If the first expression evaluates to None, then sys.stdout is used as the file for output.
print也有一个扩展形式,由上面描述的语法的第二部分定义。这个形式有时被称为“返身打印(print chevron)”。在该形式中,跟在"»"后的第一个表达式必须取值为一个"类文件"的对象,确切地说就是一个具有上面所描述的write()方法的对象。以这个扩展形式,后续表达式被打印到该文件对象上。如果第一个表达式取值为None,sys.stdout对象就被用来作为输出文件。

字数:4362    最后更新:8个月以前 [03-15 21:11]月落晨星 修改
本页编辑者:月落晨星  
[前一页]:6.3 赋值语句 Assignm…  [后一页]:6.7 return语句 The r…
[在本页中加入书签] [收藏本书] [推荐本书]
  17xie论坛 > 本书讨论区 > 本页评论   (共0条)
发表评论

用户名称 匿名发表
评论内容
验证码

关于我们 | 版权声明 | 免责声明 | 诚聘英才 | 联系我们 | 合作伙伴 | 友情链接 | 广告合作 | 提交意见
Copyright © 2007 17xie.com 互联网协同写书平台 京ICP备08002671号