随笔分类 - python基础
摘要:描述: exec 执行储存在字符串或文件中的Python语句,相比于 eval,exec可以执行更复杂的 Python 代码。 需要说明的是在 Python2 中exec不是函数,而是一个内置语句(statement),但是Python 2中有一个 execfile() 函数。可以理解为 Pytho
阅读全文
摘要:#发邮件的库import smtplib#邮件文本from email.mime.text import MIMEText#SMTP服务器SMTPServer = "smtp.163.com"#发邮件的地址sender = "15999999999@163.com"#发送者邮箱的密码passwd =
阅读全文
摘要:# python使用互译无线发送手机短信# 接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。# 账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html# 注意事项:# (1)调试期间,请用默认的模板进行测试,默认模板详见接口文档;# (
阅读全文
摘要:print(1 + 2)print("1" + "2")#不同的类型用加法会有不同的解释class Person(object): def __init__(self, num): self.num = num #运算符重载 def __add__(self, other): return Pers
阅读全文
摘要:class Person(object): def __init__(self, name, age): #属性直接对外暴露 #self.age = age #限制访问 self.__age = age self.__name = name ''' def getAge(self): return
阅读全文
摘要:from types import MethodType#创建一个空类class Person(object): __slots__ = ("name", "age", "speak")per = Person()#动态添加属性,这体现了动态语言的特点(灵活)per.name = "tom"prin
阅读全文
摘要:class Person(object): # 这里的属性实际上属于类属性(用类名来调用) name = "person" def __init__(self, name): pass #对象属性 self.name = nameprint(Person.name)per = Person("tom
阅读全文
摘要:第一类多态:from cat import Catfrom mouse import Mousefrom person import Person'''多态:一种事物的多种形态最终目标:人可以喂任何一种动物'''tom = Cat("tom")jerry = Mouse("jerry")tom.ea
阅读全文
摘要:第一类多继承的实现:from Child import Childdef main(): c = Child(300, 100) print(c.money, c.faceValue) c.play() c.eat() #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法 c.func
阅读全文
摘要:pycharm 不显示代码提示 1、检查是否代码本身有问题。 2、检查代码提示是否成功开启。 setting → Inspections → Spelling 要开启 setting → Inspections → Python 要打开 3、检查IDE省电模式是否关闭状态!!! file → pow
阅读全文
摘要:第一类单继承的实现:from person import Personfrom student import Studentfrom worker import Workerper = Person("aa", 1, 2)stu = Student("tom", 18, 12345, 110)pri
阅读全文
摘要:class Person(object): def run(self): print(self.__money) print("run") def eat(self, food): print("eat " + food) def __init__(self, name, age, height,
阅读全文
摘要:'''重写:将函数重写定义写一遍__str__():在调用print打印对象时自动调用,是给用户用的,是一个描述对象的方法。__repr__():是给机器用的,在Python解释器里面直接敲对象名在回车后调用的方法注意:在没有str时,且有repr,str = repr'''class Person
阅读全文
摘要:'''析构函数:__del__() 释放对象是自动调用'''class Person(object): def run(self): print("run") def eat(self, food): print("eat " + food) def __init__(self, name, age
阅读全文
摘要:'''self代表类的实例,而非类哪个对象调用方法,那么该方法中的self就代表那个对象self.__class__ 代表类名_'''class Person(object): def run(self): print("run") print(self.__class__) p = self.__
阅读全文
摘要:class Person(object): #name = "stu" #age = 10 #height = 160 #weight = 90 def run(self): print("run") def eat(self, food): print("eat " + food) def __i
阅读全文
摘要:class Person(object): name = "stu" age = 10 height = 160 weight = 90 def run(self): print("run") def eat(self, food): print("eat " + food) def openDoo
阅读全文
摘要:class Person(object): name = "" age = 0 height = 0 weight = 0 def run(self): print("run") def eat(self, food): print("eat" + food) def openDoor(self):
阅读全文
摘要:'''设计类类名:见名之意,首字母大写,其他遵循驼峰原则属性:见名之意,其他遵循驼峰原则行为(方法/功能):见名之意,其他遵循驼峰原则类名:Wife属性:sex age height weight faceValue行为:做饭 洗衣服 拖地 揉肩 捶腿类名:Husband属性:sex age hei
阅读全文
摘要:'''Mac:无需安装Linux:无需安装windows:勾选了pip和Add python.exe to Path'''#要安装三方模块,需要知道模块的名字#Pillow 非常强大的处理图像的工具库# pip install Pillow#windows如果报错,则输入pip install --
阅读全文

浙公网安备 33010602011771号