@SuHongjun
2020-11-17T15:38:57.000000Z
字数 1806
阅读 1180
Python
https://www.runoob.com/python3/python3-data-type.html
Python3 中有六个标准的数据类型:
Number(数字)
String(字符串)
List(列表)
Tuple(元组)
Set(集合)
Dictionary(字典)
Python3 的六个标准数据类型中:
不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组);
可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合)。
#数字类型-------加减乘除、关系运算age = 18 #整型(int)salary = 2.1 #浮点型(float)#字符串类型--------字符串只能+、*(数字)和逻辑比较name1 = 'nick'name2 = "egon">>> name3 = """nickegon""">>> name3'nick\negon'>>> str = "Hello" * 3>>> str'HelloHelloHello'>>>#列表(list)------hobby_list = ['read', 'run', '画画']>>> L = ['red', 'green', 'blue', 'yellow', 'white', 'black']>>> L[0]'red'>>> L[5]'black'>>> L[-1]'black'>>> L[2:5]['blue', 'yellow', 'white']>>> L[2:]['blue', 'yellow', 'white', 'black']#Tuple(元组)----不可修改tup2 = (1, 2, 3, 4, 5 )>>> tup3 = "a", "b", "c", "d">>> tup3('a', 'b', 'c', 'd')#Set(集合)basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}#Dictionary(字典)---键必须不可变,所以可以用数字,字符串或元组充当,而用列表就不行>>> d1 = {'Alice': 23, 'Beth': 19, 'Cecil': 32}>>> d1['Alice']23>>> d1['Alice'] = 47>>> d1['Alice']47#########空白tuple、list、set、dict>>> a = ()>>> type(a)<class 'tuple'>#单元素tuple:(1,) 后面的逗号不能少>>> a = []>>> type(a)<class 'list'>>>> a = {} #{}是空dict>>> type(a)<class 'dict'>>>> a = set() #空集合要用set()>>> type(a)<class 'set'>### dict中key - value对的增加和修改>>> d = dict()>>> d[2] = "A" #没有的key,则增加key - value对>>> d["a"] = 123 #没有的key,则增加key - value对>>> d{2: 'A', 'a': 123}>>> d[2] = 9 #已有的key,则修改key - value对>>> d{2: 9, 'a': 123}
https://www.runoob.com/python3/python3-basic-operators.html
算术运算符
比较(关系)运算符
赋值运算符
逻辑运算符
位运算符
成员运算符
身份运算符
运算符优先级
name = 'nick' #赋值,定义变量age = 19a = b = c = d = 10 #链式赋值x,y = 4,9 #交叉赋值
input()函数、print()函数
#简单应用str = input("请输入姓名:");print('Hello', str)
n = int(input("n="))print(n)n = eval(input("n=")) #与n = int(input("n="))有什么异同print(n)
输入美元、人民币互相换算
输入摄氏度,华氏度互相转换