码迷,mamicode.com
首页 > 其他好文 > 详细

类相关

时间:2019-07-12 14:21:52      阅读:21      评论:0      收藏:0      [点我收藏+]

标签:炒股   def   mysql   min   sed   ati   买车   怎么   try   

import pymysql
import redis


class Syy:
country = ‘China‘
def __init__(self):
self.money = 5000
def chaogu(self):
self.money += 50000
print(‘炒股!‘,self.money)


#节省代码
class Xs(Syy):
def chaogu(self):
super().chaogu()
print(‘唱歌‘)


sdb = Xs()
sdb.chaogu()


#ip,端口号、密码


class BaseDb:#基类
def __init__(self,ip,port,password,db):
self.ip = ip
self.port = port
self.password = password
self.db = db

def conn(self):
pass

class MySQL(BaseDb):
def __init__(self,user,ip,port,password,db):#方法重写
super().__init__(ip,port,password,db)
self.user = user
self.conn()

def conn(self):
self.conn = pymysql.connect(host=self.ip,port=self.port,user=self.user,
password=self.password,db=self.db)
self.cur = self.conn.cursor()


class Redis(BaseDb):
def conn(self):
self.r = redis.Redis(host=self.ip,db=self.db,
password=self.password,port=self.port)



class SqlServer(BaseDb):
pass

def shop(self):
    print(4s店)



def baoxian():
    print(保险公司)

def shuwuju():

    print(税务局)

def jiaoguansuo():
    print(交管所)


class BuyCar: #买车处
    def shop(self):
        print(4s)

    def baoxian(self):
        print(保险)

    def shuwuju(self):
        print(税务局)

    def jiaoguansuo(self):
        print(交管所)


class Person:
    country = China
    def __init__(self,name,leg=2):#构造函数,类在实例化的时候,自动执行的
        self.name = name #属性
        self.leg = leg
        print(self的内存地址,id(self))

    def __del__(self):#析构方法,实例被销毁的时候自动执行析构方法里面的代码。
        print(什么时候执行这里的方法呢)

    def fly(self):#方法
        print(%s在飞%self.name)
        self.bird = 猫头鹰

    def eat(self):#s
        print([%s]吃饭%self.name)
        print(我要吃【%s】%self.bird)

    @classmethod
    def saniao(cls):
        print(撒尿)


    def la(self):
        print(拉了%s次%self.count)

    def say(self):
        print(我的名字是【%s】,我有【%s】条腿%(self.name,self.leg))
        print(国籍是%s%self.country)

class Car:
    country = China
    def run(self):
        print()
        self.act()

    @classmethod
    def shuoming(cls):
        print(怎么造汽车,你猜!)
        bmw = cls()
        bmw.run()
        cls.act()

    @staticmethod
    def act():
        print(搞活动,好评送你10块钱)

    @property
    def name(self):
        select name from user
        return 大黄蜂


c = Car()
print(c.name)

 

类相关

标签:炒股   def   mysql   min   sed   ati   买车   怎么   try   

原文地址:https://www.cnblogs.com/Dorami/p/11175681.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!