Quick actions

cmd+k|ctrl+k

Navigation

Languages

21-May-2026 Lesson 10

Snippet info

Language

Python

Visibility

public

Author

michaelluiwaihung

Created

2026-05-21T12:47:47.872439Z

Updated

2026-05-21T13:50:49.454025Z

one_two_three = 123
x = 1   
#del one_two_three
def a():
    one_two_three = 10
    x = 9
    def b():
        global x
        x = x + 1
        print(x)
    b()
a()
print(x)

x = [1,2,3,4,5,6]
x.remove(2)
print(id(x))
x.clear()
print(id(x))
x = []
print(id(x))

x = [6,1,2,3,4,5]
x.sort()
y = sorted(x)
print(x,y)

x = 6,1,2,3,4,5
x = list(x)
x.sort()
x = tuple(x)
y = sorted(list(x))
print(x,y)

d = {'a' : 1, 'b' : 2}
print(d.keys())
print(d.values())
print(d.items())

x = [1,2,3,4]
print(0 in x)

d = {"a" : 1, "b" : 2}
print(1 in d.values())

try:
    x = 1
    y = x + 1
    if y == 2:
        raise
except:
    print("y is 2")
        
''' assert expression
=> if not expression:
      raise AssertionError
asset exp1, exp2
=> if not exp1:
      raise AssertionError(exp2)
'''

def a():
    print("function a")
    return False
try:
    x = 1
    y = x + 1
    if y == 2:
        assert a(), 'assertion error'
except AssertionError as msg:
    print(msg)
      
#https://glot.io/snippets/hhrnbqy42s
      
INFO