python
0 篇文章
准备工作字符串保存为文件 defsave(filename,contents):fh=open(filename,'w',encoding='utf-8')fh.write(contents)fh.close()从 URL 读取并保存二进制文件 defread_and_save_file(url,newFileName):r=requests.get(url)withopen(newFileName,'wb
定义方法返回多个参数#求 list 元素之和 defsquare_of_sum(L):constant=0sum_=0forxinL:sum_+=x*xreturnsum_,constantprint(square_of_sum([1,2,3,4,5]))a,b=square_of_sum([1,2,3,4,5])print(a,b)结果:(55,0)550python 的函数返回多值其实就是返回一个 tup