9月12日学习
可变字符串
通过使用可变字符串
下面是Demo
基本运算符
通过使用基本运算符
实际使用中,记住如下简单的规则即可,复杂的表达式一定要使用小括号组织
乘除优先加减
位运算和算术运算>比较运算符>赋值运算符
下面是Demo
>>> a=7
>>> 3<a<10
True
>>> a=0b11001
>>> b=0b01000
>>> a
25
>>> b
8
>>> c=a|b
>>> c
25
>>> bin(c)
'0b11001'
>>> bin(a&b)
'0b1000'
>>> bin(a^b)
'0b10001'
>>> a = 3
>>> a<<1
6
>>> a<<3
24
>>> a<<2
12
>>> a<<1
6
>>>
>>>> (5+10*x)/5-13*(y-1)*(a+b)/x+9*(5/x+(12+x)/y)
序列
序列是一种数据存储方式,用来存储一些列的数据,在内存中,序列就是一块用来存放多个值的连续的内存空间
列表的生成
下面是Demo
>>> a=[10,20,30,40]
>>> a[0]
10
>>> a=[]
>>> a.append(20)
>>> a
[20]
>>> a=list()
>>> a
[]
>>> a=list('gaoqi')
>>> a
['g', 'a', 'o', 'q', 'i']
>>> range(10)
range(0, 10)
>>> a=range(10)
>>> type(a)
<class 'range'>
>>> list(a)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(0,10,1))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(3,20,2))
[3, 5, 7, 9, 11, 13, 15, 17, 19]
>>> list(range(20,3,-2))
[20, 18, 16, 14, 12, 10, 8, 6, 4]
>>> list(range(-13,-33,-1))
[-13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -32]
>>> a=[x*2 for x in range(5)]
>>> a
[0, 2, 4, 6, 8]
>>> a=[x*2 for x in range(100)]
>>> a
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198]
>>> a=[x*2 for x in range(100) if x%9==0]
>>> a
[0, 18, 36, 54, 72, 90, 108, 126, 144, 162, 180, 198]
>>>