![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python3
神奇蝈蝈
这个作者很懒,什么都没留下…
展开
-
【Python3 练习题_01】元素去重(列表、集合)
1–常规方式:list1 = [1,1,2,3,4,5,6,7,7]new_list = []for element in list1: if element not in new_list: new_list.append(element)print(new_list)2–利用集合特性:list1 = [1,1,2,3,4,5,6,7,7]set1 = s...原创 2018-12-10 17:47:36 · 310 阅读 · 0 评论 -
【Python3 练习题_02】列表元素反转
list.reverse()print(list)原创 2018-12-10 17:52:52 · 394 阅读 · 0 评论 -
【Python3 练习题_03】列表推导式的应用(二维列表赋值)
# n维列表n = int(input("Enter the values of n: ")) list_n = []for i in range(n): list_n.append([int(x) for x in input().split()])print(list_n)运行结果:Enter the values of n: 32 3 4 53 4 5 64 5...原创 2018-12-11 16:20:12 · 957 阅读 · 0 评论 -
【Python3 练习题_04】抽取字符串中的数字重新组合并打印
# 打印为字符串file = open("./String.txt")content = file.read()digit_str = ""for i in content: if i.isdigit(): digit_str += iprint(digit_str)file.close()# 打印为列表file = open("./S原创 2018-12-11 17:28:03 · 326 阅读 · 0 评论 -
【python3 练习题_05】遍历序列(列表、字符串、元组)、字典
遍历两个序列(字符串、列表、元组):zip(序列a, 序列b)#!/usr/bin/env python3keys = ["Key1", "Key2", "Key3"]values = ["Value1", "Value2", "Value3"]for x,y in zip(keys,values): print("{} 对应 {}".format(x,原创 2018-12-11 17:52:24 · 622 阅读 · 0 评论 -
【Python3 练习题_06】验证字符串是否是回文
通过反转字符串来比较#!/usr/bin/env python3s = input("Enter the string: ")z = s[::-1]if s == z: print("Yes, it's a ")else: print("no")原创 2018-12-12 11:05:56 · 337 阅读 · 0 评论 -
【Python3 练习题_07】文件处理(open的使用)
文件处理# 打开文件(当前目录下的file.txt文件)fobg = open("./file.txt", )'''关于open 模式:r 以只读模式打开(默认)w 以写方式打开a 以追加模式打开 (从 EOF 开始, 必要时创建新文件)r+ 以读写模式打开,可读可写,文件不存在则报错,内容覆盖w+ 以读写模式打开,可读可写,文件不存...原创 2019-01-15 16:33:55 · 362 阅读 · 0 评论 -
【Python3 练习题_08】文件处理(常用函数)
file.read([size]) # 默认读全部file.readline() #读取整行,包括\nfile.readlines() #读取所有行并返回列表file.seek(offset[, whence]) # 设置文件当前位置file.tell() # 返回文件当前位置file.writelines(sequence) # 写入序列字符串列表,如需换行需自己加...原创 2019-01-15 16:40:06 · 156 阅读 · 0 评论