首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

程序员偷偷深爱的 9 个不良编程习惯

程序员偷偷深爱的 9 个不良编程习惯 我们曾经都做过这样的事情:当妈妈不注意的时候,偷偷地吃糖果零食,然后导致有了蛀牙。同样的,我们都违背过一些编程的基本规则,并且都会坚定地表示这种行为是不可取的。但我们就是偷偷爱着这些不良的编程习惯。 我们对所谓的编程规则嗤之以鼻,输出的代码也很糟糕——但我们依然活着。编程上帝没有下闪电劈死我们,我们的电脑也没有爆炸。事实上,只要我们能编译和发布代码,客户似乎就很满意了。 这是因为糟糕的编程不像安装电路或者摸老虎屁股那样有直接的危害性。大多数时间里它也是可以工作的。规则通

010

Python数据分析(中英对照)·Classes and Object-Oriented Programming类和面向对象编程

Our emphasis has been and will be on functions and functional programming,but it’s also helpful to know at least something about classes and object-oriented programming. 我们的重点一直是函数和函数编程,但至少了解一些类和面向对象编程也是很有帮助的。 In general, an object consists of both internal data and methods that perform operations on the data. 通常,对象由内部数据和对数据执行操作的方法组成。 We have actually been using objects and methods all along,such as when working with building types like lists and dictionaries. 事实上,我们一直在使用对象和方法,例如在处理列表和字典之类的构建类型时。 You may find at some point that an existing object type doesn’t fully suit your needs, in which case you can create a new type of object known as a class. 在某些情况下,您可能会发现现有的对象类型并不完全满足您的需要,在这种情况下,您可以创建一种称为类的新对象类型。 Often it is the case that even if you need to create a new object type,it is likely that this new object type resembles,in some way, an existing one. 通常情况下,即使需要创建新的对象类型,该新对象类型也可能在某种程度上类似于现有对象类型。 This brings us to inheritance, which is a fundamental aspect of object-oriented programming. 这就引出了继承,这是面向对象编程的一个基本方面。 Inheritance means that you can define a new object type, a new class, that inherits properties from an existing object type. 继承意味着您可以定义一个新的对象类型,一个新的类,它继承现有对象类型的属性。 For example, you could define a class that does everything that Python’s built-in lists do, and then add an additional method or methods based on your needs. 例如,您可以定义一个类来完成Python内置列表所做的一切,然后根据需要添加一个或多个附加方法。 As a quick reminder of how we’ve been using methods so far,let’s define a list, ml, which consists of a sequence of numbers. 为了快速提醒我们到目前为止是如何使用方法的,让我们定义一个列表ml,它由一系列数字组成。 If I wanted to sort this list, I can use the sort method which is provided by the ml object, a list. 如果我想对这个列表进行排序,我可以使用由ml对象(列表)提供的排序方法。 If I now look at the contents of the list,we can see that the values have been sorted. 如果我现在查看列表的内容,我们可以看到这些值已被排序。 Let’s look at an example of how to create a new class,essentially a new type of Python object. 让我们看一个如何创建一个新类的示例,本质上是一个新类型的Python对象。 A class is defined using the class statement. 类是使用class语句定义的。 Class,

02

模块简介

上一篇我们写了一个基本的代码框架也宣告我们由C++进入了C++,这节我们根据上篇笔记用到最多的cin和cout初步了解类对象的知识,类是OPP编程的核心概念之一。 类是用户定义的数据类型,要定义类,需要描述它有什么数据和对数据可以执行哪些操作,类之于对象相当于类型之于变量。类是描述,对象是数据规范创建的实体,比如老师如果作为类,他们他的数据大概是主教学科 年龄 身高 薪资 班级 而操作应该是上课 布置作业 下课 等等 cout是一个类对象,他是一个ostream类对象描述了ostream对象表示的数据和可以进行的操作,如将字符数字插入到流当中,同样cin是一个istream类对象,也是在iostream中定义的。ostream和istream类没有被我们定义,但我们可以通过包含类库文件使用它。类指定了对类对象执行的所有操作,,要对特定对象执行这些允许的操作,需要发送一条消息。如果希望cout对象显示一个字符串,一种是通过使用类方法 一种是重新定义运算符。 比如cout<<"重新定义运算符"<<endl;

01
领券