- 博客(9)
- 收藏
- 关注
原创 python注意事项
python注意事项1.缩进问题:每一个缩进都可能会导致有bug,因此要格外注意缩进、对齐、空格问题。(尤其是循环体下的空格,一定要对齐,一般是缩进4格)2.标点符号的使用小结:逗号后面要有空格,冒号也是,...
2020-06-29 09:57:29 1107
原创 python1_6函数
一、自定义函数# 第一种方式def Sum(x,y=1): return x+y # 注意这种方法一定要有返回值res = Sum(1, 2)print(res) 如图所示1.二、第二种方法y = lambda x: x**2res = y(2)print(res)如图所示2.注意:如果形参x给赋值,形参y也要赋值,否则会报错。...
2020-03-16 21:47:22 457
原创 python1_5字典
知识点:1.键-值成对出现,其中 键不可以变,也不可以重复,可以是数值、字符串。而值可以修改,可以是列表。2.用键来索引值。一、通过键来访问值dic = {'h': 'hello', 0.5: [0.3, 0.2], 'c': 'world', 'h': 0.5}res = dic['h'] # 字典中的元素无先后顺序,通过键来访问值如图所示1.二、键值对的修改dic = {...
2020-03-16 21:00:06 198
原创 python1_4字符串
# 字符串string = "My name"string = '''My name'''string = 'My name' # 字符串可以是单、双、三引号,三引号可以空行res = string[1] # 字符串的索引res = string[:2]print(res)如图所示1,注意是string[1]是指第二个字母。string = 'My name' ...
2020-03-16 20:42:14 207
原创 python1_3冒泡排序法
1.python逻辑控制符# Python逻辑控制符res = 1 < 2print(res)res = 1 < 2 < 3print(res)res = 'Name' == 'name'print(res)res = 'M' in 'magic'print(res)如图所示1.2.if 条件# 条件判定语句if 1 < 2: p...
2020-03-16 00:28:12 85
原创 python1_2列表(3)列表推导式
for循环:# for循环x = [] # 空列表for i in range(10): # 取不到10 x.append(i) # print(x)print(x)如图所示1。列表推导式# 列表推导式b = [i for i in range(1, 11)] # 从range()中取出ic = [i**2 for i in range(1, 11)]...
2020-03-16 00:08:00 404
原创 python1_2列表(2)
列表增删改查1.增all_in_list = [0.3, 'hello', True]all_in_list.append('hello world') # 新增元素print(all_in_list)运行结果2.插入all_in_list = [0.3, 'hello', True]all_in_list.insert(0, 'hala madrid') # 在0位置插入...
2020-03-08 22:22:47 709
原创 python1_1(以写的方式打开文件)
string = 'hello world'f = open('hello.txt', 'w') #以写的方式打开文件f.write(string) #将字符串写入被打开的文件中f.close() #关闭文件这是以写的方式打开,如果没有这个txt文件,则会写出来,如图所示。...
2020-03-08 21:59:33 1001
原创 python1_2列表(1)
列表(list)的性质:1.列表中每个元素可变。2.列表中每个元素有序。3.列表中元素可以是任何对象。all_in_list = [0.3, 'hello', True]print(all_in_list) # 打印列表res = all_in_list[0] # 列表索引,索引列表中0位置print(res)res = all_in_list[0: 2] # 列表切片,左闭...
2020-03-08 21:57:43 270
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人