Simple usage of python definition class

How to use python-defined classes:

Use the "obj=class name ()" statement to instantiate the class, and then use "obj. function name" to call various functions defined in the class

Examples are as follows:

Instantiate the Bili class, and then you can use the functions in the class

Content expansion:

Class definition

#! /usr/bin/env python
# coding:utf8
 
 
classHotel(object):"""docstring for Hotel"""
 def __init__(self, room, cf=1.0, br=15):
 self.room = room
 self.cf = cf
 self.br = br
 
 def cacl_all(self, days=1):return(self.room * self.cf + self.br)* days
 
if __name__ =='__main__':
 stdroom =Hotel(200)
 big_room =Hotel(230,0.9)
 print stdroom.cacl_all()
 print stdroom.cacl_all(2)
 print big_room.cacl_all()
 print big_room.cacl_all(3)

Recommended Posts

Simple usage of python definition class
The usage of wheel in python
Analysis of usage examples of Python yield
Usage of os package in python
Python decorator simple usage example summary
The usage of tuples in python
Free definition of python drawing legend
The usage of Ajax in Python3 crawler
Detailed usage of Python virtual environment venv
7 features of Python3.9
The meaning and usage of lists in python
Detailed explanation of the usage of Python decimal module
Python3 built-in module usage
Detailed explanation of Python web page parser usage examples
Basics of Python syntax
Python advanced usage summary
Basic syntax of Python
Basic knowledge of Python (1)
Prettytable module of python
MongoDB usage in Python
09. Common modules of Python3
Summary of ubuntu usage
Consolidate the foundation of Python (4)
Python implements simple tank battle
Python high-order function usage summary!
Consolidate the foundation of Python(7)
In-depth understanding of python list (LIST)
Subscripts of tuples in Python
Python analysis of wav files
Consolidate the foundation of Python(6)
Python parses simple XML data
python king of glory wallpaper
Python implements simple tic-tac-toe game
Consolidate the foundation of Python(5)
Analysis of Python Sandbox Escape
Some new features of Python 3.10
Deep understanding of Python multithreading
Analysis of Python object-oriented programming
Python version of OpenCV installation
9 feature engineering techniques of Python
matplotlib of python drawing module
Python method of parameter passing
Consolidate the foundation of Python (3)
Collection of Python Common Modules
Python high-order function usage summary!