写在开头,基本知识

1. python代码,三个''' '''是换行;""" """可以表示多行注释

2.replace('b','%') 将字符串的b换为%

3.字符串格式化,向一个字符串中插入内容

  '含有%s的字符串'%'要插入的字符串',    将%s替换

       '含有{}的字符串'.format('要插入的字符串'), 将{}替换

4.截取数据   a = "abcdefgsfdg" print(a[4:7])  左含右不含

5.数据结构,以某些特定的形式存储数据

    列表:[a,b,c,d]    字典:{a:b,c:d}

 元组:(a,b,c,d)    集合{a,b,c,d}

6.ctrl+alt+/ 格式化代码

7.在列表中可以进行嵌套[a,b,[c,h,k]],写多个[]就可以了

8.列表的增删

  列表.append(增加的内容)  列表.remove(删除的内容)

9.python的判断,电脑也会思考喔

  if  判断条件:   执行代码

  else: 执行代码

10/python的循环

   for循环

   for i in a_list: 

     print(i)

       for i in range(1,11):

          print(i)

11.函数

  内建函数:type()   int()   str()  len()  round()  input()

  自己创建的函数:def 函数名(参数): 函数内容

         函数(参数1,参数2,参数3);

    函数(参数1=传入1,参数2=传入2,参数3=传入3)

    函数(传入1,传入2,参数3=传入3)

    尽量使用前两种调用的方法

12.读excel文件:

  第三方库的安装  在cmd中 pip install xlrd  

#打开工作簿
xlsx = xlrd.open_workbook('d:/作业.xls')
#
==============读数据============ #找到sheet,两种方法 table = xlsx.sheet_by_index(0) #table2 = xlsx.sheet_by_iname('作业') #根据行列获取单元格的值 #print(table.cell_value(1,0)) print(table.cell(3,0).value) print(table.row(1)[0].value)

13.写excel文件:

  第三方库的安装  在cmd中 pip install xlwt 

import xlwt
#创建新的工作簿 new_workbook
= xlwt.Workbook()
#添加sheet work_sheet
= new_workbook.add_sheet('目录')
#往单元格中写内容 work_sheet.write(0,0,
'test') new_workbook.save('d:/test.xls')

14.往文件中添加有格式的数据,第三方库xlutils,一种excel模板

猜你喜欢

转载自www.cnblogs.com/sunflying/p/13378541.html