基础关键字

  1. 1、global—声明全局变量
  2. 2、not、and、or—逻辑运算符

Python中的关键字有

'false', 'none', 'true', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'

1、global—声明全局变量

函数体内修改全局变量在函数外不会生效,可以使用global在函数体内声明为全局变量

num = 100
def testA():
    global num		#global声明
    num = 200
    print("函数体内num=",num)

testA()
print("函数体外num=",num)

2、not、and、or—逻辑运算符

not、and、or为逻辑运算符

运算符 描述 备注
not 相当于“反义词”
and 条件同时为真,才可以是真
or 条件有一个为真,结果就为真
三个逻辑运算符的优先级为:
not > and > or

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 tanglx@aliyun.com

×

喜欢就点赞,疼爱就打赏