Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 680 Bytes

QuickCodes.md

File metadata and controls

49 lines (35 loc) · 680 Bytes

Python Quick Codes

Mixed quick codes

Codes will be categorized as they increase 🤔

Operations On A Global Variable

A Code With Error
counter = 0
def increase():
   counter += 1

increase()
print(counter)

Error:

Traceback (most recent call last):
  File "temp.py", line 8, in <module>
    increase()
  File "temp.py", line 5, in increase
    counter+=1
UnboundLocalError: local variable 'counter' referenced before assignment
Error-free Code
counter = 0
def increase():
   global counter
   counter += 1

increase()
print(counter)

# Output: 1