兵种:python程序员。
等级:二级。
攻击:较高。
防御:普通。
价格:低。
天赋:胶水,我方有c程序员时,速度可达到c程序员的80%。
天赋:成熟,难以升级到三级,即使成功也没什么好处
—–刘鑫Mars
#Types
a = 2 # integer
b = 3.0 # float
c = 5.3e5 #exponential
d = 6.5 + 0.5j # complex
e = 7 > 5 # boolean
f = 'helloword' # string
# Lists
a = ['red', 'blue', 'green']
b = list(range(5))
c = [nu**2 for nu in b]
d = [nu**2 for nu in b if nu <3]
e = c[0]
f = c[1:2]
g = ['re', 'bl'] + ['gr']
h = ['re']*5
['re','bl'].index('re') #returns index of 're'
're' in ['re', 'bl'] #true if 're' in list
sorted([3,4,1]) #returns sorted list
----
列表中的元素可以是相同的类型,也可以是不同类型的。
a =[1, "b", 3, 6, "google", True]
-----列表中插入或者删除元素-----
a.insert(3, "fire") #插入到类别中第四个位置
a.append("ch") # 插入到列表的最后面
del a[2] #删除列表中的第三个元素
['Hi!'] * 4 ['Hi!', 'Hi!', 'Hi!', 'Hi!'] 重复
列表操作包含以下函数:
1、cmp(list1, list2):比较两个列表的元素
2、len(list):列表元素个数
3、max(list):返回列表元素最大值
4、min(list):返回列表元素最小值
5、list(seq):将元组转换为列表
列表操作包含以下方法:
1、list.append(obj):在列表末尾添加新的对象
2、list.count(obj):统计某个元素在列表中出现的次数
3、list.extend(seq):在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表)
4、list.index(obj):从列表中找出某个值第一个匹配项的索引位置
5、list.insert(index, obj):将对象插入列表
6、list.pop(obj=list[-1]):移除列表中的一个元素(默认最后一个元素),并且返回该元素的值
7、list.remove(obj):移除列表中某个值的第一个匹配项
8、list.reverse():反向列表中元素
9、list.sort([func]):对原列表进行排序
Tuple
元组是不能增加或删除元素,类似于常量。
(2,) #一个元素的元组
# Dictionaries
字典是一种映射,从key 到value 的一种映射。
a = {
'red': 'rouge', 'blue':'bleu', 'green': 'vertet'}
b = a['red'] #字典取值
c = [value for key, value in a.items()]
d = a.get('yellow', 'no translation found')
#Strings
字符串其实是一个特殊的列表,列表中每个元素是一个字符。字符串本质上是一个常量,可以查询,不能修改。
a = 'red'
char = a[2]
'red' + 'blue'
'1, 2, three'.split(',') # split string into list
'.'.join([