Jump to content

EZ question about python V2

ManosMax13

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
Share on other sites

Link to post
Share on other sites

This used to work and now it doesnt whats wrong?

2020-05-03_00h45_17.png

Link to comment
Share on other sites

Link to post
Share on other sites

I just restarted the kernel and it worked why would it do that?

Link to comment
Share on other sites

Link to post
Share on other sites

python 2 doesn't have brackets for print.

print x

you should use python 3 though.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Sauron said:

python 2 doesn't have brackets for print.


print x

you should use python 3 though.

I am using python 3

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, ManosMax13 said:

I am using python 3

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

image.png.ed7682694fa4b4cea04a91bdb6219063.png

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
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 comment
Share on other sites

Link to post
Share on other sites

51 minutes ago, ManosMax13 said:

Btw do you know why some things dont work until resetting the kernel?

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

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

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 comment
Share on other sites

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

×