1.小记1 (c1.py)
# 表达式
# 1.表达式(Expression)是运算符(operator)和操作数(operand)所构成的序列。
# 2.若表达式有赋值符号(=),就要考虑右结合;如果没有赋值符号,就是左结合。
# a = 1
# b = 2
# c = 3
# print(a + b * c) #7 (*号的优先级大于+)
# print(a or b and c) #1 (and的优先级大于or)
# d = a or b
# print(d) #1 (or的优先级高于=)
# 3.优先级
# 3.1 算数 > 比较 > 逻辑(not>or)
# 3.2 逻辑运算符的优先级 (not > and >or)
# 3.3括号能辅助理解优先级;括号还能改变优先级关系
# a = 1
# b = 2
# c = 2
# d = (not a) or ((b + 2) == c)
# print(d)
# 4.推荐编辑器
# pycharm,vscode,sublime
# IDE Integrated Development Enviroment
# 5.vscode
# 5.1字体(等基础设置)设置
# 文件 ==》 首选项 ==》 设置
# 5.2保存为.py文件,通过 ctrl+` 快捷键打开命令行, 关闭命令行也是通过 ctrl+`
# 5.3也可通过 右键 ==》 在终端打开
# 5.4智能感知,断点调试
# 5.5建议安装的插件 python、Terminal、vscode-icons
# python:智能感知,python语法编写规范提示
# Terminal:使在vscode中写的代码能同步到别的编辑器,例如在vscode中写小程序的代码,在小程序编辑器中看写后的效果。
# vscode-icons:会安装一些美化的icon图标
# 5.6重命名, 选中文件 ==> 再 按F2
# 5.7一个tab等于几个空格设置 文件 ==》 首选项 ==》 设置
# snippet 片段 (大部分IDE都有) (快速构建代码片段)
# 6.Python语法的一些规范
# 6.1末尾无需分号(;)
# 6.2流程控制语句以及类和函数的定义;
# 无需{}来包裹一个代码块,Python中是靠缩进来区分代码和代码块
# 流程控制语句: 条件控制, 循环控制, 分支
# if else for while
# 6.3注释
# 6.3.1单行注释 通过 # 井号来实现; (在vscode中通过快捷键 ctrl+/ )
# 6.3.2多行注释通过(""" 这里写注释内容 """)一对三引号; (在vscode中通过快捷键 alt+shift+a )
# mood = True
# if mood :
# print('go left')
# else:
# print('go right')
# 6.4在条件语句中,
# 6.4.1没有{}来包裹代码块;
# 6.4.2是通过4个空格来区分代码块的;
# 6.4.3条件结束,通过冒号结束(语法的标识符),建议这冒号前不加空格;
# 6.4.4具有相同的缩进的代码块,视为统一代码块
# 6.4.5所以Python代码不能进行压缩;
# 现在在云服务的时代(代码都托管在自己的服务器上,也不存需要加密防止别人破译)
# 商业授权(桌面应用程序),就需要加密
# 6.4.6 if 后边的条件还可是一个条件表达式(只要条件表达式可以转为一个bool值即可)
# a = 1
# b = 2
# c = 2
# if a or b + 1 == c :
# print('go left')
# else:
# print('go right')
# 6.4.7 if 可以单独使用,else不能单独使用
# 6.4.8 if 中可以进行if嵌套
# 6.4.9 如果当if中的代码块的内容比较多的话,应该考虑分装为一个函数,用这个封装过的函数来代替,这样代码会比较清爽;
# 6.5变量(小写,推荐单词之间通过下划线连接)
# constant (常量),在Python中没有真正意义上的常量,但对于常量建议将所有字母大写
# module(模块)
# 6.6在运算符和变量之间有空格,在else语句结束后再来一个空行
# 6.7 pass 空语句,占位语句
# 7.# 优先级:算数(+,-,*,/,%,//,**) > 比较(关系,==,+=) > 逻辑(not > and > or)
2.小demo (c2.py)
# 模拟用户输入账号密码
account = 'qiyue'
password = '123456'
print('please input account')
user_account = input()
print('please input password')
user_password = input()
if account == user_account and password == user_password:
print('success')
else:
print('fail')
3.小记2 (c3.py)
# 1.apple orange banana shopping
# 输入的input里的是str,需要转一下类型
# a = input()
# print(a)
# print(type(a))
# b = int(a)
# if b == 1:
# print('apple')
# elif b == 2:
# print('orange')
# elif b == 3:
# print('banana')
# else:
# print('shopping')
# 2.d 或 e不可能同时为False,返回d 和 e中的为真的那个值
d = 1
e = 0
c = ''
# 2.1一般思路,都会想着用if else
# if d:
# c = d
# else:
# c = e
# 2.2在Python中还有or运算符,比if else 更方便
# c = d or e
(备注:以上内容来自七月老师的学习笔记,仅作为学习使用)