随笔分类 -  Python基础

摘要:导入numpy包进行科学计算 直接上代码 import numpy as np #使用numpy得到一个二维矩阵 a = np.array([1,2,3]) print(a,type(a)) # [1 2 3] <class 'numpy.ndarray'> a1 = np.array([[1,2, 阅读全文
posted @ 2022-04-21 00:10 a-tao必须奥利给 阅读(57) 评论(0) 推荐(0)
摘要:文件操作 读取文件 1.操作文件的第一种方式(读文件) f = open('a.txt',encoding='utf-8') content = f.read() #<class 'str'> print(content,type(content)) #释放资源 f.close() #释放后调用资源 阅读全文
posted @ 2022-04-19 08:21 a-tao必须奥利给 阅读(53) 评论(0) 推荐(0)
摘要:类的定义 import urllib.request ··· class MyClass: '''一个简单的实例类''' i = 12345 def f(self): return 'hello,world!' ··· 实例化类 x = MyClass() 访问类的属性和方法 print("MyCl 阅读全文
posted @ 2022-04-18 08:24 a-tao必须奥利给 阅读(51) 评论(0) 推荐(0)
摘要:range 范围 str = range(10) # 范围是 0 — 9 print(str) ste1 = range(3,9) for i in ste1: print(i) python 推导式 列表推导格式为: 格式一: 表达式 for 变零 in 列表 格式二: 表达式 for 变零 in 阅读全文
posted @ 2022-04-18 08:18 a-tao必须奥利给 阅读(71) 评论(0) 推荐(0)
摘要:题目使用python实现九九乘法表 通过预习后,使用python一行实现九九乘法表 for i in range(10): if i == 0: continue else: for j in range(i+1): if j == 0: continue else: print(i, "*", j 阅读全文
posted @ 2022-04-18 08:15 a-tao必须奥利给 阅读(54) 评论(0) 推荐(0)
摘要:python提供了一个命令去下载安全的工具包 pip install 由于我们语言是外国人开发的,很多工具包都是在国外的网站上,所以下载很慢 这时候就需要我们去修改下载源 import requests import keyword 定义一个变量 shou_id = 1 print(shou_id) 阅读全文
posted @ 2022-04-18 08:12 a-tao必须奥利给 阅读(37) 评论(0) 推荐(0)