python入门练习
LFX今天发财了吗
这个作者很懒,什么都没留下…
展开
-
浮点数的精度问题
A. 用Python计算9.4 - 9得到的结果为0.40000000000000036。B. 结果用32位浮点数表示为:0 01111101 1001 1001 1001 1001 1001 101这是因为尾数只能保存23位,尾数最低位应该“0舍1入”,所以结果如上。C. 下面分析为何Python计算9.4-9的结果为0.40000000000000036:本人的计算机中存储的浮点数采用的是双精度浮点数,那么+9.4转换为二进制即23×1.00101100110(0110循环),用64位浮原创 2021-09-19 13:12:35 · 348 阅读 · 0 评论 -
python-使用 threading 模块创建线程-两个例子
1.用threading模块的Thread类来创建thread对象——thread_obj,向target参数传递要执行的函数名(而非调用函数),用列表的方式向args传递函数用到的实参,用字典的方式向kwargs传递函数用到的关键字实参。2.用thread_obj.start()创建新线程来调用相应的函数。主线程在程序开头处开始,在print(“退出主线程”)处结束,第二个线程在thread_obj.start()时创建,在函数print_time()开头处开始,在结尾处结束。3.用thread_ob原创 2020-08-26 22:26:25 · 549 阅读 · 0 评论 -
python-从Excel到CSV的转换程序
#Excel到CSV的转换程序import openpyxl, os, csv#遍历文件夹中的文件,跳过非excel文件os.chdir("F:\\python_work\\automate_online-materials\\excelSpreadsheets")print("loop through the excel file in thr directory...")for filename in os.listdir('.'): if not filename.endswith原创 2020-08-24 08:44:12 · 220 阅读 · 0 评论 -
12.13.3电子表格单元格翻转程序
编写一个程序,翻转电子表格中行和列的单元格。例如,第 5 行第 3 列的值将 出现在第 3 行第 5 列(反之亦然)。#! python3#翻转表格import openpyxl#读取旧表格中的数据,放入一个嵌套的列表print("loading the file...")wb1 = openpyxl.load_workbook("F:\\python_work\\CSDN\\example.xlsx")sheet1 = wb1.activedata_list = []print("re原创 2020-08-18 23:05:24 · 203 阅读 · 0 评论 -
soup.select()与find_all()的实例
douban.html文件的部分内容如下,要把电影的片名、评分、评价人数、链接整理出来1、用select()方法整理import bs4, requestsfile_object = open('F:\\python_work\\CSDN\\douban.html', 'rb') #以二进制形式打开文件soup = bs4.BeautifulSoup(file_object, features='html.parser')linkTitle = soup.select('.title') .原创 2020-08-14 11:42:31 · 682 阅读 · 0 评论 -
8.5项目 生成随机的测验试卷文件
#生成随机试卷及其答案文件import random#各州及其对应的首府放入capital字典中capitals = {'Alabama':'Montgomery','Alaska':'Juneau','Arizona':'Phoenix', 'Arkansas':'Little Rock','California':'Sacramento','Colorado':'Denver', 'Connecticut':'Hartford','Delaware原创 2020-08-05 10:24:28 · 172 阅读 · 0 评论 -
strip()的正则表达式版本
#strip()的正则表达式版本 import redef regular_strip(text, found_text=''): if found_text: regex = re.compile(found_text) return regex.sub('', text) else: regex = re.compile(r'^\s+|\s+$') return regex.sub('', text) tex原创 2020-08-04 16:18:14 · 546 阅读 · 2 评论