随笔分类 -  Python

note 12 集合Set
摘要:集合Set +无序不重复元素(键)集 +和字典类似,但是无“值” 创建 x = set() x = {key1,key2,...} 添加和删除 x.add('body') x.remove('body') 集合的运算符 运算符 含义 差集 & 交集 | 并集 != 不等于 == 等于 in 成员 f 阅读全文
posted @ 2019-04-28 01:10 destiny_sea 阅读(70) 评论(0) 推荐(0)
note 11 字典
摘要:字典 Dictionary +什么是字典? +一系列的"键 值(key value)"对 +通过"键"查找对应的"值" +类似纸质字典,通过单词索引表找到其相应的定义 C++:map Java:HashTable or HashMap 例如:电话本 创建字典 使用 { } 创建字典 使用 : 指明 阅读全文
posted @ 2019-04-27 23:12 destiny_sea 阅读(174) 评论(0) 推荐(0)
note10 元组
摘要:元组 Tuple +元组即不可变(immutable)列表 除了可改变列表内容的方法外,其他方法均适用于元组 因此,索引、切片、len()、print等均可用 但是,appeng、extend、del等不可用 +使用,(可以加())创建元组 my_tuple = 1,'a',3.14,True my 阅读全文
posted @ 2019-04-27 22:19 destiny_sea 阅读(192) 评论(0) 推荐(0)
note 9 列表、时间复杂度、排序
摘要:列表 List +内建(built in)数据结构(data structure),用来存储一系列元素(items) 如:lst = [5.4,'hello',2] 前向索引、后向索引、切片、拼接、成员、长度... 列表与字符串 +相同点 索引( [ ] 运算符) 切片( [:] ) 拼接( + ) 阅读全文
posted @ 2019-04-27 00:17 destiny_sea 阅读(389) 评论(0) 推荐(0)
note 8 字符串
摘要:字符串String 一个字符的序列 使用成对的单引号或双引号括起来 或者三引号""" 和 ''' 表示块注释 字符串运算 长度 len()函数 first_name = 'Michael' len(first_name) 7 拼接 + name = first_name + 'Jordan' pri 阅读全文
posted @ 2019-04-26 22:30 destiny_sea 阅读(268) 评论(0) 推荐(0)
note 7 递归函数
摘要:递归:程序调用自身 形式:在函数定义有直接或间接调用自身 阶乘:N!=1 2 3 ... N def p(n): x = 1 i = 1 while i 阅读全文
posted @ 2019-04-26 15:01 destiny_sea 阅读(227) 评论(0) 推荐(0)
note 6 函数
摘要:函数 完成特定功能的一个语句组,这组语句可以作为一个单位使用,并且给它取一个名字 通过函数名执行 数学 function(x) = x^2 2x + 1 abs(x) 求x的绝对值 定义函数 定义和调用函数 函数参数 缺省参数 返回值 函数调用完成后,返回数据 return语句终止当前函数的执行 r 阅读全文
posted @ 2019-04-26 14:01 destiny_sea 阅读(203) 评论(0) 推荐(0)
note 5 二分法求平方根,素数,回文数
摘要:+二分法求平方根 x = float(raw_input('Enter the number')) low = 0 high = x guess = (low + high ) / 2 if x 1e 5: if guess 2 阅读全文
posted @ 2019-04-26 11:17 destiny_sea 阅读(220) 评论(0) 推荐(0)
note 4 三大结构
摘要:程序流程图 顺序结构 选择结构 if if else if 语句 嵌套结构(Nested) 多分支结构(Chained) if score = 90: print 'ARM' elif score = 80: print 'B' elif score = 70: print 'C' elif sco 阅读全文
posted @ 2019-04-26 01:17 destiny_sea 阅读(187) 评论(0) 推荐(0)
note 3 变量与简单I/O
摘要:变量(Variable) 用于引用(绑定对象的标识符) 语法 变量名=对象(数值、表达式等) 增量赋值运算符 count = count + 1 简写 count += 1 标识符(Identifier) 变量,函数,模块等的名字 命名规则 任意长 包含数字和字母、下划线 首个必须是字母或下划线 大 阅读全文
posted @ 2019-04-25 23:50 destiny_sea 阅读(314) 评论(0) 推荐(0)
note 2 运算符和表达式
摘要:运算符 +、 、 、/ %求余Modulus 指数Exponent 表达式 C = 5/9 (F 32) print 5.0/9 (75 32) 自动类型转换 类型相同,结果类型不变 1/2=0 类型不同,按照以下规则进行自动类型转换 bool int float complex math模块 模块 阅读全文
posted @ 2019-04-25 22:23 destiny_sea 阅读(232) 评论(0) 推荐(0)
note 1 对象和数据类型
摘要:/ 行注释 print “Hello World” 对象 五种基本类型 字符串 (string),简记为str 使用 ' ' 或 " " 括起来的一系列字符 整数(integer),简记为int 十进制 八进制 025 十六进制 0x15 浮点数(float) 1.48 , 21.0 , 21. , 阅读全文
posted @ 2019-04-25 21:32 destiny_sea 阅读(237) 评论(0) 推荐(0)
note 0 Python介绍及Python IDE环境安装 Spyder with Anaconda
摘要:高级语言分类 编译型语言(C/C++等) 解释型语言(BASIC、Python等) Python 诞生于1989年,创始人为吉多 范罗苏姆(Guido van Rossum) Python 语言特点 +解释型语言 +设计哲学是“优雅”、“明确”、“简单” 易学、易用 可读性高 +开发哲学是“用一种方 阅读全文
posted @ 2019-04-25 21:02 destiny_sea 阅读(292) 评论(0) 推荐(0)