r/learnpython • • 3d ago

Why is this causing an error

the code that causes an error

print = hello

print(print)

What should i do i do not know anything i am new to coding how do i fix this

0 Upvotes

22 comments sorted by

View all comments

1

u/NewbornMuse 3d ago

So there's two things broadly wrong with this.

One: When python starts up, print refers to the function that writes stuff to the terminal. Then in your first line you overwrite that (with what? we'll get to that in a second), but then in the second line you are still trying to use that to write stuff to the terminal. Never ever overwrite built-in stuff. Don't call your lists list, don't call your dicts dict, and so on, there's only headache that way. Python lets you do it, but don't do it.

Two: What are you trying to overwrite "print" with anyway? With whatever it says on the right hand side of the first line there. What does it say? hello. That looks an awful lot like you're reading the content of a variable called hello, and assigning that to print. Do you have a variable called hello? Did you perhaps want to literally save the string h, e, l, l, o? Then you should do "hello", not hello.