• Python Class Example


    代码
    #! /usr/bin/env python
    #
    -*- coding:utf-8 -*-

    import os, sys

    class Workers:
    #This is a class of workers working in the company.
    def __init__(self, name, position, email, age, salary):
    self.name
    = name
    self.position
    = position
    self.email
    = email
    self.age
    = age
    self.salary
    = salary
    class ITWorkers(Workers):
    OS
    = 'WinNT'
    def __init__(self, language, *av):
    Workers.
    __init__(self, *av)
    self.language
    =language
    def work(self, n):
    if self.position == 'web creator':
    w
    = 'makes web site'
    elif self.position == 'server administrator':
    w
    = 'checks the trafic'
    elif self.position == 'programmer':
    w
    = 'writes programs'
    print '%s %s for %d, hours using %s on %s' % (self.name, w, n, self.language, self.OS)

    henley
    = ITWorkers('PHP', 'Henley', 'web creator', 'henley@livegate.com', 32, 700)
    thomas
    = ITWorkers('Python', 'Thomas', 'server administrator', 'thomas@livegate.com', 37, 900)
    gates
    = ITWorkers('C', 'Gates', 'programmer', 'gates@livegate.com', 42, 1200)

    henley.OS
    = 'Mac'
    thomas.OS
    = 'Linux'

    if __name__ == '__main__':
    henley.work(
    8)
    thomas.work(
    7)
    gates.work(
    10)

    Result

    D:\SVNTest>python test.py
    Henley makes web site
    for 8, hours using PHP on Mac
    Thomas checks the trafic
    for 7, hours using Python on Linux
    Gates writes programs
    for 10, hours using C on WinNT
    Work for fun,Live for love!
  • 相关阅读:
    OleDbCommand 的用法
    递归求阶乘
    C#重写窗体的方法
    HDU 5229 ZCC loves strings 博弈
    HDU 5228 ZCC loves straight flush 暴力
    POJ 1330 Nearest Common Ancestors LCA
    HDU 5234 Happy birthday 01背包
    HDU 5233 Gunner II 离散化
    fast-IO
    HDU 5265 pog loves szh II 二分
  • 原文地址:https://www.cnblogs.com/allenblogs/p/1822340.html
Copyright © 2020-2023  润新知