美文网首页
python 其他语句

python 其他语句

作者: zenos876 | 来源:发表于2019-09-24 23:43 被阅读0次

1. pass 什么都不做

name = 'zenos'
if name == 'zenos':
    print(name)
========================1=========================

2. del 删除

scourdrel = {
    'age': 42,
    'frist name': 'Robin',
    'last name': 'of Locksley'
}
robin = scourdrel
print(scourdrel)
print(robin)
scourdrel = None
print(scourdrel)
print(robin)
del robin
try:
    print(robin)
except NameError as e:
    print('[NameError]: ', e)
========================2=========================
{'age': 42, 'frist name': 'Robin', 'last name': 'of Locksley'}
{'age': 42, 'frist name': 'Robin', 'last name': 'of Locksley'}
None
{'age': 42, 'frist name': 'Robin', 'last name': 'of Locksley'}
[NameError]:  name 'robin' is not defined

3. exec 将字符串作为代码执行

exec('print("hello world")')
========================3=========================
hello world

4. eval 计算并返回字符串表示的表达式结果

eval('print("hello world")')
========================4=========================
hello world

相关文章

网友评论

      本文标题:python 其他语句

      本文链接:https://www.haomeiwen.com/subject/izfvuctx.html