12 2021 档案
tcp socket学习
摘要:一、客户端程序 #1 创建socketimport socketif __name__ == '__main__': client_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #2 建立连接 client_socket.connec
阅读全文
进程
摘要:import multiprocessing as muimport timeimport osdef dance(): print('当前的dance进程号',os.getpid()) print('当前的父进程号',os.getppid()) # print(os.getpid()) print
阅读全文
导入模块和包
摘要:一、导入模块三种写法 # import math# print(math.sqrt(9)) #调用的时候模块名.方法名# from math import sqrt# print(sqrt(9)) #调用时方法名from math import *print(sqrt(16)) #调用时方法名 if
阅读全文
read和readlines同时用
摘要:file_path = 'E:\python\code\learning_python.txt'with open(file_path) as filename: fileStr=filename.read() print(fileStr) filename.seek(0) >让文件指针回到开始 f
阅读全文
in用法总结
摘要:in 在python中的使用很常见,用处也很多,很强大,这里记录下几种常见的用法。 1、在 for 循环中,获取列表或者元组的每一项: >item是变量 for item in list:2、判断左边的元素是否包含于列表,类似java中的List的contains方法 >in 前面是确定的值,不是变
阅读全文
去空格几种方法
摘要:python中去掉空格的方法有以下几种 1.使用lstrip()函数去掉左边空格string = " * it is blank space test * "print (string.lstrip()) 输出结果为:* it is blank space test * 2.使用rstrip()函数
阅读全文
文件读写操作
摘要:一、读文件 filename = 'pi_digits.txt' with open(filename) as file_object: contents = file_object.read() >读取 print(contents) lines = file_object.readlines
阅读全文
类中将实例对象作为一个属性
摘要:class Car(): def __init__(self, make, model, year): self.make = make self.model = model self.year = year self.odometer_reading = 0 def get_descriptive
阅读全文
继承
摘要:创建子类的实例时,Python首先需要完成的任务是给父类的所有属性赋值。为此,子类的方法__init__()需要父类施以援手。例如,下面来模拟电动汽车。电动汽车是一种特殊的汽车,因此我们可以在前面创建的Car类的基础上创建新类ElectricCar,这样我们就只需为电动汽车特有的属性和行为编写代码。
阅读全文
类中修改属性的值
摘要:以三种不同的方式修改属性的值:直接通过实例进行修改;通过方法进行设置 下面依次介绍这些方法 1、直接通过实例进行修改 class Car(): def __init__(self, make, model, year): """初始化描述汽车的属性""" self.make = make self.
阅读全文
函数基础用法
摘要:(1)向函数传递列表 def greet_users(names): """向列表中的每位用户都发出简单的问候""" for name in names: msg = "Hello, " + name.title() + "!" print(msg) usernames = ['hannah',
阅读全文
python中字典的使用
摘要:alien_0 = {'color': 'green', 'points': 5} print(alien_0['color']) >访问字典print(alien_0['points']) 字典类型用大括号,里面是{‘’key‘:’value’} 添加键值 alien_0['x_position'
阅读全文
python列表使用小结
摘要:1、列表操作类 插入 操作 (1)append() 在末尾追加元素 motorcycles = [] motorcycles.append('honda') (2)insert(index,A) 在任何位置插入 motorcycles = ['honda', 'yamaha', 'suzuki']
阅读全文
ubutu安装vmware步骤
摘要:Ubuntu中安装vmware tools工具 听语音 原创 | 浏览:144371 | 更新:2018-07-12 09:16 | 标签:操作系统 VMWARE 1 2 3 4 5 6 7 分步阅读 在VMware Workstation虚拟机中,如果未安装vmware tools工具,鼠标操作起
阅读全文
浙公网安备 33010602011771号