What this error want to say? Can't we use return without function?

Chris Angelico rosuav at gmail.com
Mon Sep 7 03:37:28 EDT 2020


On Mon, Sep 7, 2020 at 5:36 PM Shivlal Sharma <sshivlal9601 at gmail.com> wrote:
>
> On Monday, 7 September 2020 at 12:57:16 UTC+5:30, Python wrote:
> > Shivlal Sharma wrote:
> > > N = int(input("enter a positive integer:"))
> > > coun = 1
> > > while (N > 0):
> > > coun = coun * N
> > > N = N - 1
> > > return coun
> > > nice = ntime(N)
> > > print(nice)
> > >
> > >
> > > error: return outside of the function
> > What did you expect return out of a function to even mean?
> I mean that can't we use return keyword outside of the function?

Well... no. What do you expect it to mean? It's like asking "why can't
I use 'else' without 'if'?" - there'd need to be some meaning for it.

ChrisA


More information about the Python-list mailing list