随笔分类 - Python
摘要:# 99乘法表for i in range(1,10): for j in range(1,i+1): print(f'{j}*{i}={i*j}',end='\t')#制表符 使得更整齐 print(' ')
阅读全文
摘要:print(1,2,3,end='')# 不换行,一行内 输出下一列的值 print(4) ''' 1 2 34 '''
阅读全文
摘要:phone1_3=int(phone1[:3]) if not phone1.isdigit(): print("非法输入") else: if len(phone1)!=11: print("非法输入") else: if phone1_3>=130 and phone1_3<=150: prin
阅读全文
摘要:l=sorted([36, 5, -12, 9, -21]) print(l) ''' [-21, -12, 5, 9, 36] ''' l=sorted([36, 5, -12, 9, -21],key=abs) print(l) ''' [5, 9, -12, -21, 36] ''' # 按照
阅读全文
摘要:# 去掉空白的字符 def not_empty(s): return s and s.strip() l=list(filter(not_empty, ['A', '', 'B', None, 'C', ' '])) print(l) ''' ['A', 'B', 'C'] '''
阅读全文
摘要:# 求x的平方的列表 l = list(map(lambda x: x*x, [1, 2, 3, 4])) print(l)# [1, 4, 9, 16] names = ['adam', 'LISA', 'barT'] formatted_names = list(map(lambda x: x.
阅读全文
摘要:# 自动生成 1 2 3 l=list(range(1,4)) print(l) #求 1*1 2*2 3*3 l2=[] for x in range(1,4): l2.append(x*x) print(l2) # 简化 print([x * x for x in range(1, 4)]) #
阅读全文
摘要:# 字符串的for 循环 str1 = 'abc' for i in str1: print(i) ''' a b c ''' # 字典的for 循环 dict1 = {'name':'fqs','age':18,'address':'beijing'} for key in dict1: prin
阅读全文
摘要:str1='abcd' stat省去0_num_end = str1[:2] print(stat省去0_num_end) stat_num_end省去結尾的下标 = str1[2:] print(stat_num_end省去結尾的下标) ''' ab cd ''' def trim(s): if
阅读全文
摘要:def hanoi(n, source, target, auxiliary): if n > 0: # 将 n-1 个盘子从源柱子移动到辅助柱子 hanoi(n-1, source, auxiliary, target) # 将最大的盘子从源柱子移动到目标柱子 print("Move disk",
阅读全文
摘要:from typing import Union my_list:list[Union[str,int]]=[1,2,"it",'it'] my_doc:dict[str,Union[str,int]]={'name':'周',"age":31} print(my_list,my_doc)
阅读全文
摘要:class Phone: producer="IT" def call_by_5g(self): print("父类使用5g网络进行通话") # 定义子类 class MyPhone(Phone): producer = 'TO' def call_by_5g(self): print("自己的手机
阅读全文
摘要:class Phone: IMEI=2020001 producer="apple" def call_by_4g(self): print("4g通话") class NFCReader: nfc_type="第五代" producer="apple" def read_card(self): p
阅读全文
摘要:class Phone: IMEI=2020001 producer="apple" def call_by_4g(self): print("4g通话") class Phone2023(Phone): face_id="2233" def call_by_5g(self): print(f"20
阅读全文
摘要:class Phone: __current_voltage=3 #当前手机运行的电压 def __keep_single_core(self):#让手机单核运行的方法 print("让CPU以单核模式运行") def call_by_5g(self):#定义一个共有的方法 调用私有的方法和属性 i
阅读全文
摘要:class Student:#创建一个类 name=None age=None tel=None def __init__(self,name,age,tel):#构造函数 self.name=name self.age=age self.tel=tel print("student类创建了一个对象
阅读全文
摘要:class student: name=None def say_hi(self,msg): print(f"大家好呀,我是:{self.name},{msg}") stu=student() stu.name='fqs' stu.say_hi("我想死大家了") #设计一个闹钟 class Clo
阅读全文
摘要:student_info={ 15:{'jack','rose',}, 18:{'jj'}, 35:{'a','b','c','d'}, } age_counts = {}# 定义一个字典 key=age value=name的长度 for age in student_info: count =
阅读全文
摘要:import os os.system('mspaint D:\\1\\1.png') print('after call') ''' 打开一个图片 关闭后输出 after call '''
阅读全文
浙公网安备 33010602011771号