current position:Home>How IOS developers learn Python Programming 15 - object oriented programming 1
How IOS developers learn Python Programming 15 - object oriented programming 1
2022-02-01 01:10:15 【Sissy's father】
This is my participation 11 Yue Gengwen challenges 15 God , Check out the activity details :2021 The last time Gengwen challenge .
object-oriented programming (Object Oriented Programming
), abbreviation OOP
, It's a kind of programming idea .
What's the difference between process oriented and object oriented ?
- Process oriented : Write code from top to bottom according to business logic ;
- object-oriented : Bind data to functions , encapsulate . Reduce the rewriting process of repeated code .
Class and object introduction
class
It's an abstract concept , just Templates
. A collection used to describe objects with the same properties and methods . such as :
- The company can be expressed as a class .
The existence of a specific thing , It can be seen and touched in the real world . such as :
Ali
Represents a specific member of the company . This is the object .
The relationship between classes and objects
In development , We can classify objects .
such as , Analyze the characteristics of class students and classify them :
option = {
title: {
text: ' Zhang San ',
subtext: ' Class two in three years '
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c}%"
},
toolbox: {
feature: {
dataView: {readOnly: false},
restore: {},
saveAsImage: {}
}
},
series: [
{
name:' Funnel diagram ',
type:'funnel',
left: '10%',
top: 60,
//x2: 80,
bottom: 60,
width: '80%',
// height: {totalHeight} - y - y2,
min: 0,
max: 100,
minSize: '0%',
maxSize: '100%',
sort: 'descending',
gap: 2,
label: {
show: true,
position: 'inside'
},
labelLine: {
length: 10,
lineStyle: {
width: 1,
type: 'solid'
}
},
itemStyle: {
borderColor: '#fff',
borderWidth: 1
},
emphasis: {
label: {
fontSize: 20
}
},
data: [
{value: 60, name: ' hobby '},
{value: 40, name: ' grade '},
{value: 20, name: ' Age '},
{value: 80, name: ' Gender '},
{value: 100, name: ' full name '}
]
}
]
};
Copy code
that , We can classify the public characteristics of the students in class two of three years . And build a student class :
option = {
title: {
text: ' Class two in three years '
},
tooltip: {},
series: [
{
type: 'graph',
layout: 'none',
symbolSize: 70,
label: {
show: true
},
edgeSymbol: ['circle', 'arrow'],
edgeSymbolSize: [4, 10],
edgeLabel: {
fontSize: 10
},
data: [{
name: ' Students in class 2, grade 3 ',
x: 300,
y: 300
}, {
name: ' Zhang Si ',
x: 800,
y: 300
}, {
name: ' Li San ',
x: 500,
y: 100
}, {
name: ' Wang two pock marks ',
x: 550,
y: 500
}],
// links: [],
links: [{
source: 0,
target: 1
}, {
source: 0,
target: 2
}, {
source: 0,
target: 3
}],
lineStyle: {
opacity: 0.9,
width: 2,
curveness: 0.2
}
}
]
}
Copy code
Composition of classes
Class by 3 Parts make up :
- The name of the class : Class name
- Attributes of a class : A set of data
- Class method : Methods that allow operations on classes
️ Be careful : Class names are usually humped , Try to make the literal meaning reflect the role of class . Python
Use class
Keyword to define the class , Its basic structure is as follows :
class Class name :
pass
Copy code
Python
in , You can create objects according to the defined classes :
Object name = Class name ()
Copy code
Define a complete class :
# Definition
class Class name :
def Method name (self, Parameters ): # Function in class : Called method
pass
# perform
s = Class name () # Create objects ( example ) The whole process is instantiation
s. Method name ( Parameters ) # Call the method in the class
Copy code
Object initialization
When defining a method in a class , You will find that the system helps us automatically create self
Parameters , And when the method of the object is called , There is no need to pass in self
Parameters . So this one self
What is it? ?
actually , We need to be clear self
Two concepts of :
self
Itself is a formal parameter ;self
It's the object itself .
__init__()
Called initialization method , It can also be called construction method . When you create an object , The method is executed automatically , Set initial values for the properties of the object :
class Student(object):
def __init__(self,name,age):
self.name = name
self.age = age
def info(self):
print(self.name,self.age)
ls = Student(" Li Si ",18)
ls.info()
Copy code
__str__()
When printing out object variables , Print customized content at the same time , Pass custom content through return Keywords return :
class Students:
def __init__(self):
self.name = " Li Si "
self.age = 18
def __str__(self):
return self.name
ls = Students()
print(ls) # Li Si
Copy code
️ Be careful : The return value must be a string .
copyright notice
author[Sissy's father],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202010110126454.html
The sidebar is recommended
- Python avatar animation, come and generate your own animation avatar
- leetcode 1884. Egg Drop With 2 Eggs and N Floors(python)
- leetcode 1910. Remove All Occurrences of a Substring(python)
- Python and binary
- First acquaintance with Python class
- [Python data collection] scrapy book acquisition and coding analysis
- Python crawler from introduction to mastery (IV) extracting information from web pages
- Python crawler from entry to mastery (III) implementation of simple crawler
- The apscheduler module in Python implements scheduled tasks
- 1379. Find the same node in the cloned binary tree (Java / C + + / Python)
guess what you like
-
Python connects redis, singleton and thread pool, and resolves problems encountered
-
Python from 0 to 1 (day 11) - Python data application 1
-
Python bisect module
-
Python + OpenGL realizes real-time interactive writing on blocks with B-spline curves
-
Use the properties of Python VTK implicit functions to select and cut data
-
Learn these 10000 passages and become a humorous person in the IT workplace. Python crawler lessons 8-9
-
leetcode 986. Interval List Intersections(python)
-
leetcode 1860. Incremental Memory Leak(python)
-
How to teach yourself Python? How long will it take?
-
Python Matplotlib drawing pie chart
Random recommended
- Django paging (II)
- Concurrent. For Python concurrent programming Futures or multiprocessing?
- Programmers over the age of 25 can't know a few Chinese herbal medicines. Python crawler lessons 9-9
- Python crawler from introduction to pit full series of tutorials (detailed tutorial + various practical combat)
- The second bullet of class in Python
- Python object oriented programming 03: class inheritance and its derived terms
- How IOS developers learn Python Programming 13 - function 4
- Python crawler from introduction to mastery (VI) form and crawler login
- Python crawler from entry to mastery (V) challenges of dynamic web pages
- Deeply understand pandas to read excel, TXT, CSV files and other commands
- Daily python, Chapter 18, class
- "I just want to collect some plain photos in Python for machine learning," he said. "I believe you a ghost!"
- Django view
- Python implements filtering emoticons in text
- When winter comes, python chooses a coat with temperament for mom! Otherwise, there's really no way to start!
- Python crawler - get fund change information
- Highlight actor using Python VTK
- Python crawler actual combat: crawling southern weekend news articles
- leetcode 406. Queue Reconstruction by Height(python)
- leetcode 1043. Partition Array for Maximum Sum (python)
- Python * * packaging and unpacking details
- Python realizes weather query function
- Python from 0 to 1 (day 12) - Python data application 2 (STR function)
- Python from 0 to 1 (day 13) - Python data application 3
- Numpy common operations of Python data analysis series Chapter 8
- How to implement mockserver [Python version]
- Van * Python! Write an article and publish the script on multiple platforms
- Python data analysis - file reading
- Python data De duplication and missing value processing
- Python office automation - play with browser
- Python series tutorial 127 -- Reference vs copy
- Control flow in Python: break and continue
- Teach you how to extract tables in PDF with Python
- leetcode 889. Construct Binary Tree from Preorder and Postorder Traversal(python)
- leetcode 1338. Reduce Array Size to The Half(python)
- Object oriented and exception handling in Python
- How to configure load balancing for Django service
- How to embed Python in go
- Python Matplotlib drawing graphics
- Python object-oriented programming 05: concluding summary of classes and objects