Write a common mistake.
Many methods are defined, but no class is defined.
There was a source with a lot of methods, and the functionality was huge.
Someone said that there was no problem with software that runs Python as a function.
If you don't create a useless instance, you wonder why there isn't one at all.
I "Ah...Why is there no class in this source? "
Opponent "What is a class?"
** I didn't explain it verbally, but I was confused about it. ** **
With just the methods, you might think that Python doesn't need it because the classes are retrofitted,
"All the functionality of object-oriented programming is in Python classes," he said.
I would like you to try using the class.
[Object Oriented](https://ja.wikipedia.org/wiki/%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3% 83% 88% E6% 8C% 87% E5% 90% 91)
One of the advantages of object-oriented programming is the use of encapsulated objects that group data and methods together. The second point is that the program can be extended or partially modified by inheritance or overriding. There are two possible merits because you can be aware of object orientation just by creating a class.
If you are not a programmer and continue to copy and paste software that can use Python functions from a book, you will find that a mysterious program file is created. It's not bad, but it's the owner of the program files that has trouble modifying or extending it. As you can see, programming has a low threshold, but it is deep.
Code example
class ClassName:
def __init__(self):
name = ''
Ishikawa = ClassName()
Ishikawa.name = 'Ken'
print(Ishikawa.name)
Output result
Ken
Python is in demand on the market, and some people don't even know the meaning of the class even if it's used in the field. If you're a beginner and don't know the class, you'll find that it's easier to extend by introducing classes and modifying the code to benefit from object-orientation. At one point in my field, some people using Python didn't know the class.
** Thank you for reading the article for a long time. ** **
import sys
class Hello:
def __init__(self):
name = ''
days = 0
cost = 0
hour = 0
money = 0
# days =Days, cost=Cost, hour=Time, money=Hourly wage
World = Hello()
World.days = 20
World.cost = 4000
World.hour = 4
World.money = 832
print("¥"+"{:,}".format(World.money * World.hour * World.days - World.cost)+"Circle")
¥ 62,560
I wrote it in Python using a class. Payroll program.
Payroll program, RubyAdventCalendar2019 side
Recommended Posts