What is the meaning of % and when we should use it?
The tutorials do not mention it.
The tutorials do not mention it.
I presume you are talking about string formatting. In this case, most Python tutorials will tell you how to format/replace strings inside of other strings with various variables. An example from one tutorial:
>>> name = 'Bob'
>>> 'Hello, %s' % name
"Hello, Bob"
Here is an example using interact to show computations nicely, which is a primary way to use string formatting in Sage usefully.
However, one should point out that the new-style formatting ('Hello, {}'.format(name)
in the linked tutorial) is probably mostly recommended.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2022-01-20 15:53:25 +0100
Seen: 208 times
Last updated: Jan 20 '22
Do you mean IPython magic commands?
Or do you mean something like
5%2
, which means the remainder upon dividing 5 by 2?The most up-voted answer to https://stackoverflow.com/questions/9... explains two of the uses of
%
in Python, and another answer also discusses Jupyter/IPython magic commands.Hilarious, I have no idea why the first one that occurred to me was formatting.
Without further information, perhaps we should close the question: too imprecise.