1、对于string类型,相加+是字符串的拼接,与数字相乘(如2*),即重复两次(如b="hello",2*b="hellohello");
2、type(a)求a的类型
3、复数表示a=1.5+0.5j,a.real和a.imag
4、2**3表示2的3次方
5、Note that colors[start:stop]
contains the elements with indices i
such asstart<= i < stop
(i
ranging from start
to stop-1
). Therefore, colors[start:stop]
has (stop - start)
elements.
6、list是mutable的,可修改的,同个list中的元素类型可以不一样;因此,对于同一种数值类型的array,使用numpy模块会更加高效;
7、list的append()和pop()操作都是对于列表最后一个元素操作的;
8、list有reverse()操作,也可以通过[::-1]得到;
9、列表相加和与整数相乘的逻辑和字符串一样;
10、sorted()可以对list排序生成一个新的对象,不改变原list;如果使用list.sort()操作,则改变自身顺序;
11、A string is an immutable object;所以指向字符串的变量A,不能通过A[1]去改变;但可以使用A.replace()函数;
12、字典是无序的,有d.keys()和d.values()操作;
13、Tuples are basically immutable lists. The elements of a tuple are written between parentheses, or just separated by commas
14、Sets: unordered, unique items
15、mutable objects can be changed in place
immutable objects cannot be modified once created
16、关于python的内存管理:
对于整型数和连续字符串,只有唯一的存储空间,即a = 1和b = 1或者a = "abc"和b = "abc",a和b指向同一个内存单元;
一般而言,对于a = ..., b = a, 会使得a 和 b 指向同一个地址;要使得b仅仅复制a的内容,有浅复制和深复制两种方式,对于list中仍有list的,需要使用深复制;
----------------------------------------------------------------
17、if, elif, else
18、for i inrange(4)
19、for word in('cool','powerful','readable')
20、while/break/continue
21、a in b If b
is a dictionary, this tests that a
is a key of b
.
22、You can iterate over any sequence (string, list, keys in a dictionary, lines in a file, …)
23、对于字符串message,message.split()会返回一个list包含其中的word
24、for index,item in enumerate (words) (words是个序列)
25、for key,val in sorted (d.items()) (d是字典,针对key来排序)
26、[i**2 for i in range(4)]
----------------------------------------------------------------
27、“global” variables cannot be modified within the function, unless declared global in the function.
28、def variable_args(*args,**kwargs):
*args
: any number of positional arguments packed into a tuple**kwargs
: any number of keyword arguments packed into a dictionary
-