# example.py # assert_stmt ::= "assert" expression ["," expression] defis_admin(user_roles): assertisinstance(user_roles,list) and user_roles != [], "No user roles found"
assert'admin'in user_roles, "No admin role found." print("You have full access to the application.")
上面的表达式其实等价于
1 2 3 4 5 6
defis_admin(user_roles): if__debug__: assertisinstance(user_roles,list) and user_roles != [], "No user roles found" if__debug__: assert'admin'in user_roles, "No admin role found." print("You have full access to the application.")