1. pycharm里面快速将代码格式规整的快捷键
1) 快捷键: Ctrl + Alt + L
2) 页眉 :Code -> Reformat Code
2. pycharm 设置自动换行显示
1) 只对当前文件有效的操作
菜单栏 -> View -> Active Editor -> Use Soft Wraps;
2)如果想对所有文件都生效,需要在setting 里设置
File -> Setting -> Editor -> General -> Use soft wraps in editor。
3. python3 中判断变量是否为空
判断变量是否为空:
方式一:
if not x:
方式二:
if x is None:
同理: 判断变量有值:
方式一:
if x:
方式二:
if not x is None:
推荐使用:方式二
多个变量时:
# a = 1
# b = 2
# c = None
# if a and b:
# print('有值')
#
# if a and c:
# print('a and c 有值')
# else:
# print('ac 不全有值')
转载: