Python


都是本人一个一个字敲出来的,献给大家,kez

解决问题6个步骤

  • 分析问题
  • 划分边界IPO
    Input, Process, Output
  • 设计算法
  • 编写程序
  • 调试测试
  • 升级维护

命名

  • 大小写字母\数字\下划线和汉字
  • KaTeX parse error: Undefined control sequence: \首 at position 18: …olor{red}{大小写敏感\̲首̲字符非数字\不与保留字相同}
and elif import r a i s e \color{red}{raise} raise global
as else in return n o n l o c a l \color{red}{nonlocal} nonlocal
a s s e r t \color{red}{assert} assert except i s \color{red}{is} is try True
break finally lambda while False
c l a s s \color{red}{class} class fo not w i t h \color{red}{with} with None
continue from or y i e l d \color{red}{yield} yield
def if pass del

缩进

  • 语 法 的 一 部 分 \color{red}{语法的一部分} 语法的一部分
  • 表达包含和层次关系的唯一手段
  • 程序内长度一致即可

注释

  • 单行注释 #123123
  • 多行注释 ‘’‘开头 结尾’’’

数据类型

  • 整数类 123123
  • 字符串 “123,123”

    由0个活多个字符组成
    正向递增序号/反向递减序号

    0~n    /  -n~1

    • 索 引 : < 字 符 串 > [ M ] 第 M 个 \color{red}{索引:<字符串>[M]第M个} 索引:<字符串>[M]第M个
    • 切 片 : < 字 符 串 > [ M : N ] 第 M 到 N − 1 个 \color{red}{切片:<字符串>[M:N]第M到N-1个} 切片:<字符串>[M:N]第M到N−1个 注意是冒号!!
  • 列表[123,123]
    • 判断元素是否在列表中 in
TempStr[-1] in ['C','c']

分支语句

  • if elif else

    • if …: elif: else:
    • 冒号及后续缩进表示所属关系
  • 紧凑形式<表达式1>if<表达式2>else<表达式3>
print("猜{}了".format("对" if guess==9 else "错"))

函数

<函数名>(<参数>)