hi,
How do I make the hello function become blue in jupyter notebook or console? it should be blue as it is a function to be defined in the subsequent row. In the CS50P lecture 5 note, the hello word is in blue, as follows:
Thanks.
hi,
How do I make the hello function become blue in jupyter notebook or console? it should be blue as it is a function to be defined in the subsequent row. In the CS50P lecture 5 note, the hello word is in blue, as follows:
Thanks.
For anyone wondering what this is about because no link is included, the code rendered with syntax highlighting can be seen here under ‘Testing Strings’. (I pasted it as code below.)
If you installed a good version modern Jupyter on your machine successfully, it should just work.
One suggestion is to clear your browser cache. I would probably also suggest disabling any browser extensions and reboot and do a hard reresh on the browser page when you return. With the limited detail provided, it is hard to advise you much more than that.
In addition to those suggestions, I can though provide two ways to compare and contrast to your experience. It may help you track down the issue if you chose to really pursue it.
Go to the ‘Try Jupyter’ page here and click on either of the tiles for ‘JupyterLab’ or ‘Jupyter Notebook’ in the upper left-to-middle of page area.
When the Jupyter session opens, paste in your code and you’ll see it has the proper syntax highlighting.
It will also work in a markdown cell if you put a line with three back ticks followed by python
above it, like so ```python
and then make a line below it and put three back ticks to close the formatting.
(Note though that code won’t work there without modification because input()
is one of the few things not supported by the experimental JupyterLite without adjustment as spelled out here.)
Go here and click on the ‘launch binder
’ bage. A temporary session will spin up on a remote machine served by MyBinder. (It will take a bit more time than JupyterLite. Be patient.)
When that comes up open a new notebook and paste in your code. You’ll see the syntax highlighting works as well. And the code will run in that cell just fine.
As discussed above, it will also render the hello
function as blue. (I am seeing the rendered markdown not quite render the in-use input()
and print()
like the code cell, but these are nuances of CodeMirror, I think and different ways in the cell code and markdown handled/rendered.)
Note that in reply, I said qualified things with ‘good’ version of Jupyter. There is always a chance syntax highlighting got messed up in the course of new developing; however, I haven’t seen a lot
Minor:
By the way, screenshots are generally not a way to convey all the information and should not be relied upon solely as you did. For example, if you pasted in the actual code here and used markdown to syntax highlight it, you should see it is rendered just fine here with ‘hello()’ getting colored like other functions:
def main():
name = input("What's your name? ")
hello(name)
def hello(to="world"):
print("hello,", to)
if __name__ == "__main__":
main()
Please read Getting good answers to your questions and follow it as a guide for future posts. The information linked at the bottom How do I ask a good question?, has particularly good information on not relying on images. I understand here you were trying to show a behavior, and so a screenshot was appropriate, but only as a supplement. You want others, including ‘the future you’, to be able to find answers and images aren’t indexed by these services. Plus, you want to help others trying to help you. So enable them immediately test your code, they don’t want to retype your example when you could have easily pasted it.