zoukankan      html  css  js  c++  java
  • Python类和实例调用

    self指向的是实例对象,作为第一个参数,使用时不需要传入此参数。

    class Student(object):
        #定义一个Student类,
        def __init__(self, name, score,age):
            self.name = name
            self.score = score
            self.age = age
        def print_score(self):
            #定义类方法,实例对象可调用
            return self.name,self.score
        def get_grade(self):
            if self.score >= 90:
                return 'A'
            elif self.score >= 60:
                return 'B'
            else:
                return 'C'
        
    st1 = Student('lingyummu',67,25)
        #创建一个Student类对象st1
    print(st1.name,st1.age,st1.score)
    print(st1.print_score())
    print(st1.get_grade())

    读书和健身总有一个在路上

  • 相关阅读:
    tcp socket http(复制的)
    cas php
    占用字节
    网络基础
    Mbps MB/S Mb/s
    path_info和get_full_path()的区别
    rbac权限管理
    ORM _meta
    Django SQLite3的使用
    url的分发
  • 原文地址:https://www.cnblogs.com/Renqy/p/11610956.html
Copyright © 2011-2022 走看看