编写一个student类,里面有学生的姓名,年龄,学号,出生日期,写一个方法,方法是read方法,我的,,,,,,,我爱学习,创建四个对象,调用方法
时间: 2024-05-03 13:20:11 浏览: 7
好的,我明白了。 以下是 Python 代码实现:
```python
class Student:
def __init__(self, name, age, student_id, birthdate):
self.name = name
self.age = age
self.student_id = student_id
self.birthdate = birthdate
def read(self):
print(f"{self.name}({self.student_id}), {self.age}岁,出生日期为{self.birthdate}。我爱学习!")
student1 = Student("张三", 20, "20210001", "2001-01-01")
student2 = Student("李四", 19, "20210002", "2002-02-02")
student3 = Student("王五", 21, "20210003", "2000-03-03")
student4 = Student("赵六", 18, "20210004", "2003-04-04")
student1.read()
student2.read()
student3.read()
student4.read()
```
输出结果如下:
```
张三(20210001), 20岁,出生日期为2001-01-01。我爱学习!
李四(20210002), 19岁,出生日期为2002-02-02。我爱学习!
王五(20210003), 21岁,出生日期为2000-03-03。我爱学习!
赵六(20210004), 18岁,出生日期为2003-04-04。我爱学习!
```
希望这能回答您的问题!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)