class Index(object):
def __init__(self,index_name,index_code,closePrice_yesterday,closePrice_today):
self.index_code=index_code
self.index_name=index_name
self.closePrice_yesterday=closePrice_yesterday
self.closePrice_today=closePrice_today def display(self):
print(("%s"+" "+"%s"+" "+"%s"+" "+"%s"+" "+"%s")% (self.index_name,self.index_code,self.closePrice_yesterday,self.closePrice_today)) def profit(self):
index_profit=(self.closePrice_today-self.closePrice_yesterday)/self.closePrice_yesterday
return index_profit index300=Index("沪深300","",5306.59,5064.82)
index50=Index("上 证50","",3347.12,3179.65)
index500=Index("中证500","",11366.29,10879.84) print("----------指数收益率计算结果---------------")
print(index300.index_name+"收益率: "+str(index300.profit()*100)+"%")
print(index50.index_name+"收益率: "+str(index50.profit()*100)+"%")
print(index500.index_name+"收益率: "+str(index500.profit()*100)+"%")

输出结果如下:

----------指数收益率计算结果---------------
沪深300收益率: -4.55603315877%
上 证50收益率: -5.00340591314%
中证500收益率: -4.27976059031%

python-面向对象(指数对象举例)的更多相关文章

  1. python面向对象中类对象、实例对象、类变量、实例变量、类方法、实例方法、静态方法

    1. 类对象和实例对象 Python中一切皆对象,Python类本身也是一种对象,类定义完成后,会在当前作用域中定义一个以类名为名字的命名空间.类对象具有以下两种操作: 可以通过“类名()”的方式实例 ...

  2. Python面向对象-获取对象信息type()、isinstance()、dir()

    type() type()函数用于判断对象类型: >>> type(11) <class 'int'> >>> type('abc') <clas ...

  3. python面向对象编程对象和实例的理解

    给你一个眼神,自己体会

  4. Python面向对象 -- slots, @property、多重继承MixIn、定制类(str, iter, getitem, getattr, call, callable函数,可调用对象)、元类(type, metaclass)

    面向对象设计中最基础的3个概念:数据封装.继承和多态 动态给class增加功能 正常情况下,当定义了一个class,然后创建了一个class的实例后,可以在程序运行的过程中给该实例绑定任何属性和方法, ...

  5. python 面向对象、特殊方法与多范式、对象的属性及与其他语言的差异

    1.python 面向对象 文章内容摘自:http://www.cnblogs.com/vamei/archive/2012/06/02/2532018.html   1.__init__() 创建对 ...

  6. 洗礼灵魂,修炼python(31)--面向对象编程(1)—面向对象,对象,类的了解

    面向对象 1.什么是面向对象 (图片来自网络) 哈哈,当然不是图中的意思. 1).面向对象(Object Oriented,OO)是软件开发方法.利用各大搜索引擎得到的解释都太官方,完全看不懂啥意思对 ...

  7. Python面向对象02/类的空间问题、类与对象之间的关系、类与类之间的关系

    Python面向对象02/类的空间问题.类与对象之间的关系.类与类之间的关系 目录 Python面向对象02/类的空间问题.类与对象之间的关系.类与类之间的关系 1. 类的空间问题 2. 类与对象之间 ...

  8. Python面向对象01 /面向对象初识、面向对象结构、类、self、实例化对象

    Python面向对象01 /面向对象初识.面向对象结构.类.self.实例化对象 目录 Python面向对象01 /面向对象初识.面向对象结构.类.self.实例化对象 1. 面向对象初识 2. 面向 ...

  9. python 面向对象专题(二):类的空间问题、类与对象之间的关系、类与类之间的关系

    https://www.cnblogs.com/liubing8/p/11308127.html 目录 Python面向对象02/类的空间问题.类与对象之间的关系.类与类之间的关系 1. 类的空间问题 ...

随机推荐

  1. 【转】Linux模式设计5-位图操作

    通过位图提供的两种状态可以在非常节约内存的情况下表示开关变量,并且同类这类变量可以紧凑而高效的统一进行处理.有很多内核子系统都需要位图的支持,但是不同的情况又需要不同的位图个数,比如SMP系统上的CP ...

  2. SqlServer将表中数据复制到另一张表

    insert into phone2(ph,attr,type,carrier) select top 1000 ph,attr,type,carrier from phone 将表phone的字段和 ...

  3. [leetcode]_String to Integer (atoi)

    非常考虑思维全面性的一道题,考验是否能够考虑本问题的方方面面. 题目:将一个string转换为int.实现函数atoi()的功能. 先应该明确atoi()有哪些特殊功能:(正常的正负数情况我就不列了) ...

  4. 关于overflow-y:scroll ios设备不流畅的问题

    最近做双创项目的时候因为页面有很多数据显示,所以打算让它Y轴方向滚动条的形式展现,但在测试阶段发现IOS设备滑动效果非常不理想: search by google之后找到解决办法: -webkit-o ...

  5. 18)Java八股文名词

      >VO:   value-object >DTO: Data Transform Object >DTD: Document Type Definition      文档类型定 ...

  6. Win+R快速打开你的应用程序

    参考自:http://blog.csdn.net/nothing0318/article/details/7179405 1:在你的磁盘任意位置创建一个文件夹,比如C:MyShortcut,然后将你的 ...

  7. FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框

    FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...

  8. does not match bootstrap parameter

    问题描述: DBD::mysql object version 2.0419 does not match bootstrap parameter 2.0902 at /usr/libdata/per ...

  9. LinearRegression

    利用python实现简单的线性回归对房屋面积进行预测 # -*-coding:utf-8 -*- ''' Created on 2016年12月15日 @author: lpworkdstudy '' ...

  10. python Django 学习笔记(二)—— 一个简单的网页

    1,创建一个django项目 使用django-admin.py startproject MyDjangoSite 参考这里 2,建立视图 from django.http import HttpR ...