Jump to content

Why is it that sometimes a thing works and then when I restart jupyter notebook it has an error or just doesnt output anything

str = """song"""

x = str.lower().count("random word")

print=(x)

This doesnt do anything not even an output or an error when it used to work like a day ago why is that?

Link to comment
https://linustechtips.com/topic/1187942-ez-question-about-python-v2/
Share on other sites

Link to post
Share on other sites

7 minutes ago, Sauron said:

...why does the title say python 2 then?

image.png.ed7682694fa4b4cea04a91bdb6219063.png

Sorry i posted another question and vw2 was about the question so i can categorize them as im learning and write the number someone so i can revisit it should have wrote no2. Btw do you know why some things dont work until resetting the kernel?

Link to post
Share on other sites

In the code snippet in your post, you put

print=(x)

You then fixed that in your screenshot to

print(x)

but it was too late at that point - as soon as you ran the first snippet, the name print had been reassigned from the print function to the value of x (a number). You needed to restart the kernel for it to forget about the assignment to print and reset it back to the builtin.

 

If you ever do that again in future and want to recover without restarting your kernel, you can reassign it from the builtin using

import builtins
print = builtins.print

(python 3 only).

 

18 hours ago, Sauron said:

I don't know what "resetting the kernel" means

It looks like a Jupyter notebook, so a kernel in that context just means the state in the current python context, so what variables have been assigned etc.

HTTP/2 203

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×