Python errors All In One
2024-09-02 08:51:35
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 发布文章使用:只允许注册用户才可以访问!
最新文章
- 读书笔记--SQL必知必会09--汇总数据
- React Native填坑之旅--布局篇
- Ajax.ActionLink打开页面之后,表单验证失效
- 设计模式之Composite(组合)模式
- JavaScript开发技巧
- Django 使用原生SQL
- MDM基于IOS设备管控功能的所有命令介绍
- 教程:使用 MongoDB、WCF、OData 和 PowerBI 构建 Azure 上的商业智能解决方案
- c - 比较字符串的大小
- ios多视图开发中:xib与UIViewController的关联
- 利用PYTHON设计计算器功能
- Java+Tomcat + Idea + Jrebel 实现热部署
- LeetCode 252. Meeting Rooms (会议室)$
- Spring3 MVC使用@ResponseBody的乱码问题及解决办法
- beeswarm-蜜蜂图
- codeforces 161D Distance in Tree 树上点分治
- HDMI驱动热插拔检测方法
- java 面向对象内部类
- C++中 线程函数为静态函数 及 类成员函数作为回调函数
- Pika的设计及实现
热门文章
- 关于redis搭建环境
- __init__ raises an exception, then __del__ will still be called
- libevent之基于socket的bufferevent
- 莫队/se 优雅的暴力
- Uniter 单一框架学习
- SQL系列总结——基础篇(二)
- [SpringSecurity] UserDetailsService 详解
- .NET使用DinkToPdf将HTML转成PDF
- Codeforces Round #628 (Div. 2) C.	Ehab and Path-etic MEXs(树,思维题)
- hdu4710 Balls Rearrangement(数学公式+取模)