Weird behaviour with semicolon before function call in ipython/ipython notebook

痞子三分冷 提交于 2019-12-01 18:20:12

It's a command for automatic quoting of function args: http://ipython.readthedocs.org/en/latest/interactive/reference.html#automatic-parentheses-and-quotes

From the docs:

You can force automatic quoting of a function’s arguments by using , or ; as the first character of a line. For example:

In [1]: ,my_function /home/me  # becomes my_function("/home/me")

If you use ‘;’ the whole argument is quoted as a single string, while ‘,’ splits on whitespace:

In [2]: ,my_function a b c    # becomes my_function("a","b","c")

In [3]: ;my_function a b c    # becomes my_function("a b c")

Note that the ‘,’ or ‘;’ MUST be the first character on the line! This won’t work:

In [4]: x = ,my_function /home/me # syntax error

In your case it's quoting all characters including ' and ( and )

You get similar output here but without the single quotes:

In [279]:
;list(ab)

Out[279]:
['(', 'a', 'b', ')']
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!