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


最新文章

  1. 读书笔记--SQL必知必会09--汇总数据
  2. React Native填坑之旅--布局篇
  3. Ajax.ActionLink打开页面之后,表单验证失效
  4. 设计模式之Composite(组合)模式
  5. JavaScript开发技巧
  6. Django 使用原生SQL
  7. MDM基于IOS设备管控功能的所有命令介绍
  8. 教程:使用 MongoDB、WCF、OData 和 PowerBI 构建 Azure 上的商业智能解决方案
  9. c - 比较字符串的大小
  10. ios多视图开发中:xib与UIViewController的关联
  11. 利用PYTHON设计计算器功能
  12. Java+Tomcat + Idea + Jrebel 实现热部署
  13. LeetCode 252. Meeting Rooms (会议室)$
  14. Spring3 MVC使用@ResponseBody的乱码问题及解决办法
  15. beeswarm-蜜蜂图
  16. codeforces 161D Distance in Tree 树上点分治
  17. HDMI驱动热插拔检测方法
  18. java 面向对象内部类
  19. C++中 线程函数为静态函数 及 类成员函数作为回调函数
  20. Pika的设计及实现

热门文章

  1. 关于redis搭建环境
  2. __init__ raises an exception, then __del__ will still be called
  3. libevent之基于socket的bufferevent
  4. 莫队/se 优雅的暴力
  5. Uniter 单一框架学习
  6. SQL系列总结——基础篇(二)
  7. [SpringSecurity] UserDetailsService 详解
  8. .NET使用DinkToPdf将HTML转成PDF
  9. Codeforces Round #628 (Div. 2) C. Ehab and Path-etic MEXs(树,思维题)
  10. hdu4710 Balls Rearrangement(数学公式+取模)