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. aspx页面与服务器控件间运行原理

    一.进入服务器控件以及aspx页面前,必须的准备: a)在WebForm 中只要带有runat="server" 那么那就是一个控件. b)如果form有runat="s ...

  2. sqoop的codegen工具

    一.codegen工具的使用 sqoop codegen --connect jdbc:mysql://localhost:3306/test --username root --password 1 ...

  3. HTML5高防win8风格

    使用HTML5做了一个高防Win8的页面,大家看看怎么样 Java..NET.PHP.Android.iOS.HTML5,CSS3. web前端.视频资料下载网站  http://51pansou.c ...

  4. centos6.7下编译安装lnmp

    很多步骤不说明了,请参照本人的centos6.7下编译安装lamp,这次的架构是nginx+php-fpm一台服务器,mysql一台服务器 (1)首先编译安装nginx: 操作命令: yum -y g ...

  5. MongoDB简述

    简介 MongoDB is an open-source document database that provides high performance, high availability, an ...

  6. C++求斐波那契数

    题目内容:斐波那契数定义为:f(0)=0,f(1)=1,f(n)=f(n-1)+f(n-2)(n>1且n为整数) 如果写出菲氏数列,则应该是: 0 1 1 2 3 5 8 13 21 34 …… ...

  7. BAT命令介绍【转自Internet】

    一.简单批处理内部命令简介 1.Echo 命令 打开回显或关闭请求回显功能,或显示消息.如果没有任何参数,echo 命令将显示当前回显设置. 语法: echo [{on│off}] [message] ...

  8. delphi 2010是动画GIF的支持方法

    下面delphi 2010是动画GIF的支持方法:  1.在窗体上放一个Image1控件.注意:这时设置其Picture属性,加载一幅动画GIF是不会动画显示的.  2.在窗体的FormCreate事 ...

  9. 计算系数 (codevs 1137) 题解

    [问题描述] 给定一个多项式(ax + by)^k,给定a.b.k.n.m,请求出多项式展开后x^n y^m项的系数. [样例输入] 1 1 3 1 2 [样例输出] 3 [解题思路] 本题为NOIP ...

  10. for xml path('') 引发的数据不完整

    When you read Extensible Markup Language (XML) data from Microsoft SQL Server by using the SqlDataRe ...