Print函数()
print(‘引号里面的内容可以原样输出’),不加引号则只能是数字,而且如果是有运算符号,则会直接运算出结果,将结果输出。但是加上引号或双引号则原样输出。(因为计算机可以直接处理数学运算,不需要引号。)
‘’’ ——三引号,表示换行。
如
print('''曾经有一份真诚的爱情摆在我的面前,
但是我没有珍惜,等到了失去的时候才后悔莫及,
尘世间最痛苦的事莫过于此。
如果可以给我一个机会再来一次的话,
我会跟那个女孩子说我爱她,
如果非要把这份爱加上一个期限,
我希望是一万年!
''')
转义字符
\n 反斜杠
可以实现换行。如
print('曾经有一份真诚的爱情摆在我的面前,\n但是我没有珍惜,等到了失去的时候才后悔莫及,\n尘世间最痛苦的事莫过于此。\n如果可以给我一个机会再来一次的话,\n我会跟那个女孩子说我爱她,\n如果非要把这份爱加上一个期限,\n我希望是一万年!')
常用的转移字符:
变量
变量命名规则
=表示赋值,==表示等于一般用于判断。
第一关知识点思维导图
合并表格
import xlrd
import os
import xlwt
def get_all_file(raw_path):
all_file=os.walk(raw_path)
file_path=[]
for i in all_file:
if i[2]==[]:
continue
for each_file in i[2]:
if '.xl' in each_file:
bet_path=os.path.join(i[0],each_file)
file_path.append(bet_path)
return file_path
#找出目标文件夹下面的所有Excel表格
def hebing_xls(file_path,save_path,all_sheet=False):
workbook = xlwt.Workbook(encoding='utf-8',style_compression=0)
sheet = workbook.add_sheet("sheet1",cell_overwrite_ok = True)
num=1
for each in file_path:
data = xlrd.open_workbook(each)
#all_sheet表示是否每个表格都读取
if all_sheet==True:
sheet_num=len(data.sheet_names())
else:
sheet_num=1
for index in range(sheet_num):
table = data.sheets()[index]
hang=table.nrows
lie=table.ncols
#读取第一行,写入标题行
if num==1:
first_row = table.row_values(0)
for each in first_row:
sheet.write(0,first_row.index(each),each)
#只有标题行,没有记录,则不合并
if hang<2:
continue
else:
for i in range(hang)[1:]:
for j in range(lie):
a=table.cell(i,j).value
sheet.write(num,j,a)
num=num+1
#print (num, 'finish')
workbook.save(save_path)
if __name__ == '__main__':
raw_path=r'E:\派森教学案例库\宿舍管理明细表'
save_path=r'e:\派森教学案例库\宿舍管理明细表\all.xls'
file_path=get_all_file(raw_path)
hebing_xls(file_path,save_path,True)
print('end')
爱心输出
print('''
ovelov velove
elovelovelovelovelovelove
elovelovelovelovelovelovelo
elovelovelovelovelovelovelove
lovelovelovelovelovelovelovel
velovelovelovelovelovelovel
lovelovelovelovelovelovel
velovelovelovelovelovel
ovelovelovelovelove
ovelovelovelo
velov
o
''')