如何检查字符串是否是Python中的有效关键字?


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

for is a python keyword

geeksforgeeks is not a python keyword

elif is a python keyword

elseif is not a python keyword

nikhil is not a python keyword

assert is a python keyword

shambhavi is not a python keyword

True is a python keyword

False is a python keyword

akshat is not a python keyword

akash is not a python keyword

break is a python keyword

ashty is not a python keyword

lambda is a python keyword

suman is not a python keyword

try is a python keyword

vaishnavi is not a python keyword

如何打印所有关键字的列表?

有时候,在分配变量名时,记住所有的关键字可能是比较困难。因此,在“keyword”模块中提供了一个函数“kwlist()”,它打印所有33个python关键字。

1

2

3

4

5

6

7

8

#Python code to demonstrate working of iskeyword()

   

# importing "keyword" for keyword operations

import keyword

   

# printing all keywords at once using "kwlist()"

print ("The list of keywords is : ")

print (keyword.kwlist)

输出:

1

2

3

4

5

6

The list of keywords is :

['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']

相关推荐:《Python教程》

本篇文章就是关于检查字符串是否是Python中的有效关键字的方法介绍,希望对需要的朋友有所帮助!

以上就是如何检查字符串是否是Python中的有效关键字?的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python怎么打开文件的路径?

Python中::-1代表什么?

Python语言如何对图片进行剪切

Python+pandas分析nginx日志的实例

java script是什么?和java有什么联系?

终于介绍Python 3.9

Python3中网络编程常用模块的详解

Python单链表中如何查找和删除节点?

Python能代替shell吗

Python中list和set的区别

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...