python-面向对象(指数对象举例)
- 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-面向对象(指数对象举例)的更多相关文章
- python面向对象中类对象、实例对象、类变量、实例变量、类方法、实例方法、静态方法
1. 类对象和实例对象 Python中一切皆对象,Python类本身也是一种对象,类定义完成后,会在当前作用域中定义一个以类名为名字的命名空间.类对象具有以下两种操作: 可以通过“类名()”的方式实例 ...
- Python面向对象-获取对象信息type()、isinstance()、dir()
type() type()函数用于判断对象类型: >>> type(11) <class 'int'> >>> type('abc') <clas ...
- python面向对象编程对象和实例的理解
给你一个眼神,自己体会
- Python面向对象 -- slots, @property、多重继承MixIn、定制类(str, iter, getitem, getattr, call, callable函数,可调用对象)、元类(type, metaclass)
面向对象设计中最基础的3个概念:数据封装.继承和多态 动态给class增加功能 正常情况下,当定义了一个class,然后创建了一个class的实例后,可以在程序运行的过程中给该实例绑定任何属性和方法, ...
- python 面向对象、特殊方法与多范式、对象的属性及与其他语言的差异
1.python 面向对象 文章内容摘自:http://www.cnblogs.com/vamei/archive/2012/06/02/2532018.html 1.__init__() 创建对 ...
- 洗礼灵魂,修炼python(31)--面向对象编程(1)—面向对象,对象,类的了解
面向对象 1.什么是面向对象 (图片来自网络) 哈哈,当然不是图中的意思. 1).面向对象(Object Oriented,OO)是软件开发方法.利用各大搜索引擎得到的解释都太官方,完全看不懂啥意思对 ...
- Python面向对象02/类的空间问题、类与对象之间的关系、类与类之间的关系
Python面向对象02/类的空间问题.类与对象之间的关系.类与类之间的关系 目录 Python面向对象02/类的空间问题.类与对象之间的关系.类与类之间的关系 1. 类的空间问题 2. 类与对象之间 ...
- Python面向对象01 /面向对象初识、面向对象结构、类、self、实例化对象
Python面向对象01 /面向对象初识.面向对象结构.类.self.实例化对象 目录 Python面向对象01 /面向对象初识.面向对象结构.类.self.实例化对象 1. 面向对象初识 2. 面向 ...
- python 面向对象专题(二):类的空间问题、类与对象之间的关系、类与类之间的关系
https://www.cnblogs.com/liubing8/p/11308127.html 目录 Python面向对象02/类的空间问题.类与对象之间的关系.类与类之间的关系 1. 类的空间问题 ...
随机推荐
- SQL中补0
SQL中补0 编写人:CC阿爸 2014-3-14 第一种方法: right('00000'+cast(@count as varchar),5) 其中'00000'的个数为right函数的最后参数 ...
- linux iostat命令详解 磁盘操作监控工具
Linux系统中的 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视. 它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况. ...
- PHP常用函数和常见疑难问题解答
PHP常用库函数介绍 一.PHP字符串操作常用函数 1.确定字符串长度 int strlen(string str) 2.比较两个字符串 a. strcmp函数对两个字符串进行二进制安全的比较,并区 ...
- Like ruby of SBM Crusher zip to dict
how to use the zip to bulid a dict in python? data = """A dynamic, interpreted, open ...
- AMD平台下在Windows虚拟机中安装Mac10.8.6【Written By KillerLegend】
我的电脑CPU是AMD,以前在虚拟机中装过Windows操作系统,感觉很简单,这几天想体验一下苹果系统,未来也可能会从事Mac相关软件开发,于是从早上便兴致勃勃的开始了--于是悲剧也开始了,上网各种查 ...
- 在linux下安装Mongodb
1.到官网下载源码:mongodb-linux-x86_64-rhel55-3.2.4.gz 2.安装 创建用户组.用户.目录 [root@hadoop1 ~]# groupadd mongodb [ ...
- Java 控制台执行带自定义包定义的类,出现“Exception in thread "main" java.lang.NoClassDefFoundError: ConnectSQLServer (wrong name: sine/ConnectSQLServer)”
1.先说明一下代码实现:自定义package sine, 源代码保存路径为:E:\JSP\HibernateDemo\HibernateDemoProject\src\sine\ConnectSQLS ...
- 菜鸟学习Spring——60s使用annotation实现简单AOP
一.概述. AOP大家都知道切面编程,在Spring中annotation可以实现简单的AOP列子.下面还未大家介绍几个概念: Aspect 对横切性关注点的模块化. Advice 对横切性关注点的具 ...
- hdu 2660 Accepted Necklace
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2660 Accepted Necklace Description I have N precious ...
- 部署ghost博客
wget https://ghost.org/zip/ghost-0.6.4.zip npm install --production NODE_ENV=production npm start &g ...