xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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/

https://www.freecodecamp.org/news/if-name-main-python-example/#:~:text=We can use an if,name if it is imported.


# 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 发布文章使用:只允许注册用户才可以访问!


posted @ 2021-01-09 22:47  xgqfrms  阅读(136)  评论(1编辑  收藏  举报