Python errors All In One
Python errors All In One
SyntaxError: invalid character in identifier

\u200b, ZERO WIDTH SPACE
https://stackoverflow.com/questions/14844687/invalid-character-in-identifier
SyntaxError: invalid syntax
if__name__ == "__main__":
# if 关键字,后面加空格
if __name__ == "__main__":

用于区分,如何执行 Python 模块

https://www.jcchouinard.com/python-if-name-equals-main/
# Python program to execute
# main directly
print ("Always executed")
if __name__ == "__main__":
# 模块, 被直接执行的时候
print ("Executed when invoked directly")
else:
# 模块,被 import 使用的时候
print ("Executed when imported")
https://www.geeksforgeeks.org/what-does-the-if-name-main-do/
# Suppose this is foo.py.
print("before import")
import math
print("before functionA")
def functionA():
print("Function A")
print("before functionB")
def functionB():
print("Function B {}".format(math.sqrt(100)))
print("before __name__ guard")
if __name__ == '__main__':
functionA()
functionB()
print("after __name__ guard")

https://stackoverflow.com/questions/419163/what-does-if-name-main-do
emoji bug

$ ls
# chmod 777 / chmod 755
$ chmod +x ./dict.py
# 可执行脚本
# #!/usr/bin/python3
$ ./dict.py
# 指定解释器
$ python3 ./dict.py
#!/usr/bin/python3
# ✅ 一行 OK
# dict = {'Name': 'xgqfrms', 'Age': 18, 'Class': 'First'}
# ✅ 多行错误
dict = {
'Name': 'xgqfrms',
'Age': 18,
'Class': 'First',
'Country': 'China 🇨🇳',
}
# 更新 Age
dict['Age'] = 23
# 添加信息
dict['School'] = "Python 教程"
print ("dict['Age']: ", dict['Age'])
print ("dict['School']: ", dict['School'])
print ("dict['Country']: ", dict['Country'])
https://www.runoob.com/python3/python3-dictionary.html
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14256866.html
未经授权禁止转载,违者必究!

浙公网安备 33010602011771号