泰安有口碑的网站建设,旗县长安网站建设思路,手机兼职工作有哪些,php手机网站开发自用总结。
零散知识
1.Python的计算方法#xff1a;运算符、函数、方法
1) 方法与函数的区别#xff1a;
方法与特定类型的对象有关#xff0c;是属于某个对象的函数#xff0c;对象始终是该方法的第一个参数。e.g. islower()方法是检查字符串中字符是否为小写形式的方法运算符、函数、方法
1) 方法与函数的区别
方法与特定类型的对象有关是属于某个对象的函数对象始终是该方法的第一个参数。e.g. islower()方法是检查字符串中字符是否为小写形式的方法hello.islower()、one fish,two fish.count(fish)
函数在括号里输入参数。
2) 运算符
算术运算符 **幂 %取模 //向下取整
比较运算符
逻辑运算符and or not
成员运算符 in、not in
恒等运算符is、is not
x is None # 检查x是否为None
a [1, 2, 3]
b a
c [1, 2, 3]
print(a b) # True
print(a is b) # True
print(a c) # True
print(a is c) # False
2.赋值与一些函数
x,y,z 1,2,3
type(x)
len(x)
int(x)
float(x)
str(x)
3.print与input
name input(please enter your name:)
print(hello,name)
print(hello,\nworld)
# 不能换行
print(hello,
world)
# 一定要换行
print(hello,\n
world)
print(rhello,\n
world)
4.一些规则如果使用空格缩进就一直用空格不要用制表符
用4个空格缩进
在类之间空两行
字典、列表、元组以及参数列表中在 后一个空格
字典的后也要添加一个空格
在赋值运算符合比较运算符周围要有空格参数列表中除外但是括号里不加空格。例如a f(1,2 g(3,4)
5.变量名
普通字母、下划线、数字。
不能有空格不能以数字开头不能使用保留字或内置标识符会报错
全部使用小写字母并用下划线分隔
6. PEP8 编码规范
7.string字符串
用单双引号均可
hello, Im xx.
she said: I am fine.
I\m fine.
# 单双引号
hello world # helloworld 没空格
hello * 2 # hellohellow 每空格
数据结构
1.list列表可变、有序与字符串最相似都支持len、索引、切片、成员运算符。但列表可以改字符串不能改
Month [JAN, FEB] 中括号
切片[6:9] 取678
2.tuple元组不可变、有序Month (JAN, FEB) 小括号括号可省略dimensions 52, 40, 100
解包length, width, height dimensions
3.set集合可变、无序只包含唯一元素a {1, 2, 3} 大括号
number [1,2,6,3,1,1]
unique_nums set(number)unique_nums.add(10) : 不是append会把10放在任意位置
4.dictionary字典 可变无序存储元素对键和值键是不可变的故list不能当键
student[Amy] 数据结构的索引都是中括号
可以直接添加新键student[John] 12
检查键是否在字典中in、get 。如果预计查询会失败最好用get。
print( Amyin student)
print(student.get(Amy)) # 不存在输出None
print(student.get(Amy),not) # 不存在输出not复合字典student[Amy][age]