I couldn't catch up with my understanding in Python Learning Course IV Leave a study note while reviewing. If it's the same code, it's boring and I can't remember it I will write it with the game material of my favorite "CLOCK ZERO ~ Shuuen no Ichibyo ~". spoiler alert.
** Create a class **
Class is defined by "class class name:" Class names start with a capital letter
class CZmember:
Write pass when there is nothing in the class Align the indent
class CZmember:
pass
There is no processing, that is, it is still before the fall of 2010.
** Instantiate from class **
You can create a new instance by calling "class ()" and that class The class generated by "variable name = class ()" can be assigned to the variable
Generate an empty class
class CZmember:
pass
cz_member1 = CZmember()
Add information to your instance This time, let's use the name and age of the CZ member.
class CZmember:
pass
#Create an instance
cz_member1 = CZmember()
#Add information to your instance
cz_member1.name = 'Takato'
cz_member1.age = 12
print(cz_member1.name + 'Is' + str(cz_member1.age) +I'm old)
Takato is 12 years old
This "name" and "age" part is called an instance variable. What is the target of the game for elementary school students?
Members will be added quickly too!
class CZmember:
pass
cz_member0 = CZmember()
cz_member0.name = 'Nadeshiko'
cz_member0.age = 12
cz_member1 = CZmember()
cz_member1.name = 'Takato'
cz_member1.age = 12
cz_member2 = CZmember()
cz_member2.name = 'Riichiro'
cz_member2.age = 11
Even though there are 7 members, it's annoying to write like this. So let's add it in the item that will appear later.
** Add processing inside the class **
(Continued from time to time)
"CLOCK ZERO ~ One Second of the End ~" Because I can cry so much with the game released on Switch If you are interested, please play it.
Recommended Posts