一、下载安装
https://www.python.org/downloads/
IDE:pycharm
二、数据类型
1、数字:int、float
二进制:0b 10,转换二进制:bin(10)、bin(0b10)、bin(0o10)、bin(0x10)
八进制:0o 10,转换八进制:oct(…)
十六进制:0x 10,转换十六进制:hex(…)
2、布尔:bool
True、False(1、0)
3、字符串:str
'hello world'
"hello world"
'hello \' world'
'hello " world'
'''
hello world
hello world
'''
"""
hello world
hello world
"""
'hello \
world'
"hello"+"hello"+"hello"
"hello"*3
"hello"[0]
"hello"[0:3]
"hello"[0:-1]
"hello"[2:]
ord("w")
\n 换行
\r 回车
\' 单引号
\t 横向制表符
4、组:list
[1,2,3,4,5,6]
[1,2,"hello",False,Ture]
[[1,2,"hello",False,Ture],[1,2,"hello",False,Ture],[1,2,"hello",False,Ture]]
[1,2,3,4,5,6][0]
[1,2,3,4,5,6][0:2]
[1,2,3,4,5,6] + [1,2,3,4,5,6]
[1,2,3,4,5,6] * 2
3 in [1,2,3,4,5,6]
3 not in [1,2,3,4,5,6]
len([1,2,3,4,5,6])
max([1,2,3,4,5,6])
min([1,2,3,4,5,6])
5、元组(序列):tuple
不可变的
(1,2,3,4,5)
(1,)
(1,2,"hello",False,Ture)
6、集合:set (无序的,不会重复的)
{1,2,3,4,5,6}
set()
{1,2,3,4,5,6,7,8,6,6,6,6}
len({1,2,3,4})
1 in {1,2,3,4}
1 not in {1,2,3,4}
{1,2,3,4} - {1,2} 差集
{1,2,3,4} & {1,2} 交集
{1,2,3,4} | {1,9} 并集
7、字典:dict
{
1:1,
2:2,
3:3
}
{
'a':'aaaa',
'b':'bbbb',
'c':'cccc',
'd':'dddd'
}
{
1:'aaaa',
'1':'bbbb',
'c':'cccc',
'd':'dddd'
}
{}
{'a':'aaaa','b':'bbbb','c':'cccc','d':'dddd'}['a']