摘要: 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:SKING 4 5 """ 6 题目:购物车 7 1.启动程序后,让用户输入工资,然后打印商品列表。 8 2.允许用户根据商品编号购买商品。 9 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒。 10 4.可随时退出,退出时,打印已购买商品和... 阅读全文
posted @ 2019-01-18 14:44 SKING_Python 阅读(346) 评论(0) 推荐(0) 编辑
摘要: python3 中encode 和decode的使用方法。 编码: 将文本转换成字节流的过程。即Unicode >特定格式的编码方式,产生特定的字节流保存在硬盘中(一般为utf-8格式)。 解码: 将硬盘中的字节流转换成文本的过程。即特定格式的字节流 >Unicode。 注意: 在内存中写的所有的字 阅读全文
posted @ 2019-01-17 22:51 SKING_Python 阅读(959) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:sking 4 """ 5 test_file.txt 6 文件内容如下: 7 打印字符串第一个字符 8 9 打印字符串第二个字符 10 """ 11 #打开文件test_file.txt 12 f = open('test_file.... 阅读全文
posted @ 2019-01-15 23:16 SKING_Python 阅读(6609) 评论(0) 推荐(0) 编辑
摘要: 1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 1*7=7 2*7=14 阅读全文
posted @ 2019-01-12 20:57 SKING_Python 阅读(470) 评论(0) 推荐(0) 编辑
摘要: 1 #Python3 格式化输出 占位符%s %d %f 2 name = input("Name:") 3 age = int(input("Age:")) 4 #input默认接受的都是字符串类型,所以要输出%d整型,就要先把字符串强制转换成整型 5 job = input("Job:") 6 salary = input("Salary:") 7 8 info = ""... 阅读全文
posted @ 2019-01-12 20:52 SKING_Python 阅读(388) 评论(0) 推荐(0) 编辑
摘要: 1 #Python3 三元表达式 2 #result = 值1 if 条件 else 值2 如果条件成立result = 值1 如果条件不成立 result = 值2 3 4 a, b, c = 1, 3, 5 5 d = a if a>b else c 6 print(d) #结果:5 阅读全文
posted @ 2019-01-12 20:51 SKING_Python 阅读(1703) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:sking 4 #python3集合操作方法详解 python3集合操作大全 5 6 #集合是无序的 7 #创建集合 8 a = {1,2,3} #正确 9 b = set([1,2,3]) #正确 10 c = set((1,2,3))... 阅读全文
posted @ 2019-01-11 22:14 SKING_Python 阅读(1606) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:sking 4 #Python3字典操作详解 Python3字典操作大全 5 6 #字典是无序的(因为它没有下标),key必须是唯一的 7 #字典是可变的,可以修改和添加 8 #创建字典 9 info = {'haha':12,'heihei':13,'wo... 阅读全文
posted @ 2019-01-09 21:56 SKING_Python 阅读(5454) 评论(0) 推荐(1) 编辑
摘要: #元组可以看做是只读的列表,它和列表是差不多的,都是存储数据的结构,但是元组不能被修改、添加,只能查看、调用、切片 #元组只有两个方法 count() 和 index() tuple_01 = (1, 2, 3, 4) #统计元组中的元素出现的次数 tuple_02 = (1, 3, 3, 5, 3, 6, 3) print(tuple_02.count(3)) #4 #查看元组中的第一个出... 阅读全文
posted @ 2019-01-04 20:14 SKING_Python 阅读(749) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:SKING 4 5 #!/usr/bin/env python 6 # -*- coding:utf-8 -*- 7 #Author:sking 8 #Python3字符串操作方法详解 Python3中字符串操作方法大全 9 10 nam... 阅读全文
posted @ 2019-01-03 22:07 SKING_Python 阅读(2115) 评论(0) 推荐(0) 编辑