# py **Repository Path**: gs-code/py ## Basic Information - **Project Name**: py - **Description**: ------------------ - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-09 - **Last Updated**: 2025-04-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # python ## 变量 标准数据类型 - Numbers(数字) math 模块、cmath 模块,数学函数,随机数 int(有符号整型) long(长整型,也可以代表八进制和十六进制) float(浮点型) complex(复数) - String(字符串) 1. + 字符串连接 2. * 字符串重复输出 3. [] 通过索引获取字符串中的字符 4. [:] 截取字符串中的一部分 5. in 成员运算符,包含返回True 6. not in 如果运算符 字符串中不包含返回True - List(列表) 1. len(arr) 数组长度 2. arr[0] arr[-1] 3. list2[1:5] 截取 arr[1:] 4. list.append('Google') 添加 5. del list1[2] 删除 6. [1] * 4 重复 7. i in arr 元素是否在列表中 8. list.count(obj) 统计某个元素在列表中出现的次数 9. list.extend(seq) 数组合并 10. list.insert(index, obj) 插入 11. list.pop(index) 指定索引删除 12. arr.remove(元素) 13. arr.reverse() 反转 14. arr.sort() cmp -- 可选参数, 如果指定了该参数会使用该参数的方法进行排序。 key -- 主要是用来进行比较的元素,只有一个参数,具体的函数的参数 就 是取自于可迭代对象中,指定可迭代对象中的一个元素来进行排序。 reverse -- 排序规则,reverse = True 降序, reverse = False 升 序(默认)。 - Tuple(元组)只读list - Dictionary(字典) - 函数 ## 算数运算符 - 加 + - 减 - - 乘 * - 除 / - 取模 % - 幂 ** - 取整除 // ## 比较运算符 - == - != - > - < - >= - <= ## 赋值运算符 - = - += - -= - *= - /= - %= - **= - //= ## 位运算符 - & - | - ^ - ~ - << - >> ## 逻辑运算符 - and - or - not ## 成员运算符 - in - not in ## 身份运算符 - is - not is is 与 == 区别: is 用于判断两个变量引用对象是否为同一个(同一块内存空间), == 用于判断引用变量的值是否相等。 ## 条件语句 if 条件: 语句 elif 条件: else: 语句 ## 循环语句 ``` arr = [[1,2],[3,4],[5,6],[],[7,8]] for index,item in enumerate(arr): print(index,"---",item) for c in item: print(c) ``` ## 日期时间 ## 模块