In python 2.6, why is the following line valid?

在python 2.6中,为什么以下行是有效的?

my_line = 'foo' 'bar'

and if that is valid, why isn't the following:

如果这是有效的,为什么不是下面的

my_list = 1 2 

The first example is string concatenation, however, the following isn't valid either (thanks god):

第一个例子是字符串连接,但是,以下也不是有效的(感谢上帝):

foo = 'foo'
bar = 'bar'
foo_bar = foo bar

4 个解决方案

#1


20

This is doing string literal concatenation. As noted in the documentation, advantages include the following:

这是字符串文字连接。如文件所指出,优点包括:

This feature can be used to reduce the number of backslashes needed, to split long strings conveniently across long lines, or even to add comments to parts of strings...

这个特性可以用来减少需要的反斜杠的数量,可以方便地跨长行分割长字符串,甚至可以向字符串的部分添加注释……

It goes on to note that this concatenation is done at compilation time rather than run time.

它接着指出,这种连接是在编译时完成的,而不是在运行时完成的。

The history and rationale behind this, and a rejected suggestion to remove the feature, is described in PEP 3126.

在PEP 3126中描述了这一特性背后的历史和原理,以及一个被拒绝的删除该特性的建议。

更多相关文章

  1. Python - 去除字符串首尾填充
  2. Python处理字符串
  3. Python语言特性之1:函数参数传递
  4. python list range 字符串的截取 如 text[1:5]
  5. 在Python中使用正则表达式匹配的字符串周围添加括号
  6. 用python将二进制整数或字符串写入文件
  7. python1.返回一个字符串中出现次数第二多的单词 2.字符串中可能
  8. Python笔记(九):字符串操作
  9. python 产生随机数,随机字符串

随机推荐

  1. js关于Function.prototype.bind
  2. RichFaces 3.3.3 和 JSF 2.0
  3. js中ajax获取json数据遍历提示undefined
  4. 在单选按钮上选中/取消选中,加载/隐藏部分
  5. javascript 的MD5代码备份,跟java互通
  6. 使用AngularJS隐藏滚动div
  7. 简单实现一个文件上传的进度条
  8. 如何在当前视图中始终保持水平底部滚动条
  9. JavaScript(ES5)使用保留字作函数名
  10. JQuery纯前端导入Excel文件,兼容IE10及IE9