python定义一个人类_Python类和人类

Python中的类

俗话说,物以类聚,人以群分,类是什么,类就是一组相同属性的集合。下面来结合人,探讨Python中类和人类的关系。

首先,我们定义一个人的类,如下:

class People(object):'''创建人类'''def __init__(self,name,age,sex,blood_type):"""人具有姓名,年龄,性别,血型的属性"""self.name=name

self.age=age

self.sex=sex

self.blood_type=blood_type

def walk(self):'''创建走路方法'''print("%s can walk!!!!" %self.name)

def speak(self):"""创建说话的属性"""print("%s can speak!!" %self.name)

def learn(self):'''创建学习的属性'''print("%s is learning." %self.name)

p1= People("wupeiqi",18,"女","0")

p2= People("Alex",8,"男","AB")

上面代码中,我们定义了一个人的类,人都有姓名,年龄,性别,血型等属性,还有说话,学习,走路等方法;并且我们创建了两个人,一男一女,"Wupeiqi"和"Alex",下面我们来一步一步完善这两个人。

我们知道,男人有喉结,女人会生小孩,这两个是男,女的区别,也是各自独有的属性。那么给"wupeiqi"和"Alex"添加这种属性。如下:

class People(object):'''创建人类'''def __init__(self,name,age,sex,blood_type):"""人具有姓名,年龄,性别,血型的属性"""self.name=name

self.age=age

self.sex=sex

self.blood_type=blood_type

def walk(self):'''创建走路方法'''print("%s can walk!!!!" %self.name)

def speak(self):"""创建说话的属性"""print("%s can speak!!" %self.name)

def learn(self):'''创建学习的属性'''print("%s is learning." %self.name)

p1= People("w

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure! Thank you for asking me to deliver a speech on the topic of "Reading and Writing Ability and Technology". Ladies and gentlemen, When we talk about reading and writing ability, we think of it as essential to our daily lives. It is a skill that we learn as young children, and we continue to develop it throughout our lives. In a world where technology has become an integral part of our lives, it has also impacted our reading and writing abilities. While technology can be helpful in many ways, it can also limit our abilities to read and write effectively. Technology has profoundly impacted the way that we read and write. With the introduction of smartphones, tablets, and e-readers, reading has become more accessible and sometimes more engaging. For example, we can access a vast library of books from our devices, and we can read and listen to them on the go. However, excessive use of technology can also lead to distractions, reducing our concentration and making it harder for us to retain the information that we are reading. On the other hand, technology has enabled us to write with ease and efficiency. With word processors, we can type up pages of text in no time, and with the internet, we can now easily communicate and share our ideas with people all over the world. However, we must also be mindful of the quality of our writing. While the speed of typing may have increased, it is essential to preserve our writing skills and maintain the quality of our writing. In conclusion, it is evident that technology has both positive and negative effects on our reading and writing abilities. While it can be helpful and convenient, we must also be cautious not to lose sight of the value of reading and writing. Nurturing our ability to read and write is essential to our personal and professional growth, and we must work to preserve these skills while adapting to the advancements of technology. Thank you for listening to my speech.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值