python
变量类型
-Python有五个标准的数据类型:
·Numbers(数字)
·String(字符串)
·List(列表)
·Tuple(元组)
·Dictionary(字典)
-列表
列表用 [ ] 标识,是 python 最通用的复合数据类型,有序
list.append(‘Google’) ## 使用 append() 添加元素
del list1[2] #删除列表中元素
#!/usr/bin/python
# -*- coding: UTF-8 -*-
list = [ 'runoob', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
print (list) # 输出完整列表
print (list[0]) # 输出列表的第一个元素
print (list[1:3]) # 输出第二个至第三个元素
print (list[2:]) # 输出从第三个开始至列表末尾的所有元素
print (tinylist * 2) # 输出列表两次
print (list + tinylist) # 打印组合的列表
-元组
元组用”()”标识。内部元素用逗号隔开。元组不能二次赋值,相当于只读列表(内容不能更改!!!!!,可以整体删除),但是可以两两组合或者其他运算生成一个新的元组例:tup3=tup1+tup2。
元组中只包含一个元素时,需要在元素后面添加逗号
tup1 = (50,);
#!/usr/bin/python
# -*- coding: UTF-8 -*-
tuple = ( 'runoob', 786 , 2.23, 'john', 70.2 )
tinytuple = (123, 'john')
print (tuple) # 输出完整元组
print (tuple[0]) # 输出元组的第一个元素
print (tuple[1:3]) # 输出第二个至第三个的元素
print (tuple[2:]) # 输出从第三个开始至列表末尾的所有元素
print (tinytuple * 2) # 输出元组两次
print (tuple + tinytuple) # 打印组合的元组
-字典
字典用”{ }”标识。字典由索引(key)和它对应的值value组成,通过键取,无序
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print (dict['one']) # 输出键为'one' 的值
print (dict[2]) # 输出键为 2 的值
print (tinydict) # 输出完整的字典
print (tinydict.keys()) # 输出所有键
print (tinydict.values()) # 输出所有值
dict['Age'] = 8; # update existing entry
dict['School'] = "DPS School"; # Add new entry
del dict['Name']; # 删除键是'Name'的条目
dict.clear(); # 清空词典所有条目
del dict ; # 删除词典
-不一样的运算符
**幂 返回x的y次幂 a**b 为10的20次方, 输出结果 100000000000000000000
// 取整除 - 返回商的整数部分 9//2 输出结果 4 , 9.0//2.0 输出结果 4.0
is 和is not
>>> a=1
>>> b=1
>>> a is b
True
>>> a==b
True
>>> a=b=1
>>> a is b
True
>>> a=1
>>> b=a
>>> a is b
True
>>> a=[1,2]
>>> b=a
>>> a is b
True
>>> b=a[:]
>>> a is b
False
-数学函数
import math
dir (math) #查看里面
math.
import cmath
dir (cmath)
cmath.sqrt(-1)