% syntax in Python [duplicate]

江枫思渺然 提交于 2021-02-08 03:02:02

问题


I was working on a project in which I had to write

%matplotlib inline 

at the beginning to solve a problem.

But I'm wondering what does this "%" stands for: is it an operator ? Has it a name so I could do some researches about it ?


回答1:


You are not looking at standard Python code.

You are almost certainly using an IPython interactive session, and it uses % as a prefix to recognize special commands, called magic functions. Type %quickref to get a quick reference. From that reference:

%magic : Information about IPython's 'magic' % functions.

Magic functions are prefixed by % or %%, and typically take their arguments without parentheses, quotes or even commas for convenience. Line magics take a single % and cell magics are prefixed with two %%.

If you then type in %magic you'll find the reference documentation for available magic functions, including:

%matplotlib:

 %matplotlib [gui]

Set up matplotlib to work interactively.

This function lets you activate matplotlib interactive support at any point during an IPython session. It does not import anything into the interactive namespace.



来源:https://stackoverflow.com/questions/26736436/syntax-in-python

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