[Tutor] Misc question about scoping

Alan Gauld alan.gauld at btinternet.com
Thu Jun 3 19:10:41 CEST 2010


"Tino Dai" <oberoc at gmail.com> wrote

>    Is there a way to express this:
>    isThumbnail = False
>    if size == "thumbnail":
>        isThumbnail = True
>
>     like this:
>     [ isThumbnail = True if size == "thumbnail" isThumbnail = 
> False ]

Bob showed one way, you could also do:

isThumbnail = True if size == "thumbnail" else False

>     and the scoping extending to one level above without resorting 
> to the
> global keyword?

Not sure what this has to do with scoping or the use of global?
global is only needed inside a function if you are modifying a
value defined outside the function.

If the assignment is inside a function and the definition of
isThumbnail is outside then you need to use global.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list