So I made a function to open sites:
import webbrowser
def go_to_url(link):
global YT, Reddit, SO
YT = 'youtube.com'
Reddit = 'reddit.com'
SO = 'stackoverflow.com'
webbrowser.open(link)
go_to_url(YT)
No syntax error when running, but returns result:
NameError: name 'YT' is not defined
Later I tried to define the variables outside the function and it worked:
import webbrowser
def go_to_url(link):
webbrowser.open(link)
YT = 'youtube.com'
Reddit = 'reddit.com'
SO = 'stackoverflow.com'
go_to_url(YT)
I just don't understand why can't I define it inside my function, even if they are global anyway. Please explain it to me, thanks in advance!