GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python_test/test16.py at master · Hanlen520/python_test Expand file tree/ Copy pathtest16.pyMore file actions 42 lines (34 loc) · 1013 Bytes / Copy pathtest16.pyFile metadata and controls42 lines (34 loc) · 1013 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #!/usr/bin/env python3 # -*- coding: utf-8 -*- ' 练习面向对象的类和实例 ' __author__ = 'sergiojune' # 定义学生实例 class Student(object): def __init__(self, name, score): ' 初始化实例,当创建实例时被调用这个函数,所以在实例化时需要传入这个函数的参数 ' self.name = name self.score = score def get_grade(self): '对数据进行封装' print('my name is %s' % self.name) if self.score > 90: print('your grade is A') elif self.score > 75: print('your grade is B') else: print('your grade is C') # bart = Student() # print(bart) # # 给实例初始化名字属性和成绩 # bart.name = 'bart june' # bart.score = 98 # print(Student) # print(bart.name) # print(bart.score) # 实例化 tom = Student('Tom', 87) print(tom.name) print(tom.score) bob = Student('Bob', 65) # 调用实例方法 bob.get_grade() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |