Python Forum
local variable 'option' referenced before assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
local variable 'option' referenced before assignment
#4
(Jan-22-2018, 07:01 AM)RedSkeleton007 Wrote: I never understood the code statement "while true". While what is true?
In python, true is written True with a capital T. The while True idiom means loop indefinitely. It may seem strange but it's simple logic: a while condition: loop runs until the condition becomes false. The True condition never becomes false, so while True loops indefinitely, without the need to add a new keyword such as repeat in the language.

C programmers traditionally write while(1) to loop indefinitely. This is the ancestor of python's while True. The latter is cleaner from a purist's point of view because a condition is a boolean rather than an integer. However even python uses 1 for True and 0 for False, for example
>>> True + 1
2
but
>>> True is 1
False
Reply


Messages In This Thread
RE: local variable 'option' referenced before assignment - by Gribouillis - Jan-22-2018, 07:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  It's saying my global variable is a local variable Radical 5 1,257 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  local varible referenced before assignment SC4R 6 1,598 Jan-10-2023, 10:58 PM
Last Post: snippsat
  UnboundLocalError: local variable 'wmi' referenced before assignment ilknurg 2 1,970 Feb-10-2022, 07:36 PM
Last Post: deanhystad
  Referenced before assignment finndude 3 3,333 Mar-02-2021, 08:11 PM
Last Post: finndude
  ReferenceError: weakly-referenced object no longer exists MrBitPythoner 17 11,789 Dec-14-2020, 07:34 PM
Last Post: buran
  Assignment of non-existing class variable is accepted - Why? DrZ 6 4,359 Jul-13-2020, 03:53 PM
Last Post: deanhystad
  UnboundLocalError: local variable 'figure_perso' referenced before assignment mederic39 2 2,304 Jun-11-2020, 12:45 PM
Last Post: Yoriz
  local variable 'marks' referenced before assignment Calli 3 2,364 May-25-2020, 03:15 PM
Last Post: Calli
  Variable assignment wierdness with Memory eoins 1 2,072 Mar-08-2020, 10:15 AM
Last Post: scidam
  UnboundLocalError: local variable referenced before assignment svr 1 3,350 Dec-27-2019, 09:08 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020