[Introduction to Python3 Day 11] Chapter 6 Objects and Classes (6.1-6.2)

6.1 What is an object?

--All objects contained in Python are objects --Objects contain both data (called variables, attributes) and code (called functions, methods). --An object represents a unique instance (entity, example) of something concrete. --An object can be thought of as a noun, and an object's method can be thought of as a verb. Objects define individual things, and methods define how they interact with others.

6.2 Class definition by class

--Objects are likened to plastic boxes, but ** classes ** are like molds ** for making such ** boxes.


#Definition of Person class
>>> class Person():
...     pass
... 
#Objects are created by calling the class name like a function.
>>> someone=Person()
>>> class Person():
...     def __init(self):
...         pass
... 

#__init__()Is a special name given to the method that initializes an individual object when it is created from the class definition. Also, when defining in a class, the first argument must be self.

#The self argument refers to the created object itself.

#Self the newly created object, another argument("Elmer Fudd")As the name of the object__init__()Call the method.
>>> class Person():
...     def __init__(self,name):
...         self.name=name
... 
>>> hunter = Person("Elmer Fudd")
>>> print("The mighty hunter:",hunter.name)
The mighty hunter: Elmer Fudd

--Inside the Person class, the name attribute is called self.name, and from outside the object (hunter) it is called hunter.name.

Impressions

I could understand the concept of objects and classes, but it was difficult to get used to the grammar ...

References

"Introduction to Python3 by Bill Lubanovic (published by O'Reilly Japan)"

Recommended Posts

[Introduction to Python3 Day 12] Chapter 6 Objects and Classes (6.3-6.15)
[Introduction to Python3 Day 11] Chapter 6 Objects and Classes (6.1-6.2)
[Introduction to Python3 Day 22] Chapter 11 Concurrency and Networking (11.1 to 11.3)
[Introduction to Python3 Day 1] Programming and Python
[Introduction to Python3 Day 13] Chapter 7 Strings (7.1-7.1.1.1)
[Introduction to Python3 Day 14] Chapter 7 Strings (7.1.1.1 to 7.1.1.4)
[Introduction to Python3 Day 15] Chapter 7 Strings (7.1.2-7.1.2.2)
[Introduction to Python3 Day 21] Chapter 10 System (10.1 to 10.5)
[Introduction to Python3, Day 17] Chapter 8 Data Destinations (8.1-8.2.5)
[Introduction to Python3, Day 17] Chapter 8 Data Destinations (8.3-8.3.6.1)
[Introduction to Python3 Day 19] Chapter 8 Data Destinations (8.4-8.5)
[Introduction to Python3 Day 18] Chapter 8 Data Destinations (8.3.6.2 to 8.3.6.3)
[Introduction to Python3 Day 23] Chapter 12 Become a Paisonista (12.1 to 12.6)
[Introduction to Python3 Day 20] Chapter 9 Unraveling the Web (9.1-9.4)
About python objects and classes
[Introduction to Python3 Day 8] Chapter 4 Py Skin: Code Structure (4.1-4.13)
[Introduction to Python3 Day 3] Chapter 2 Py components: Numbers, strings, variables (2.2-2.3.6)
[Introduction to Data Scientists] Basics of Python ♬ Functions and classes
[Introduction to Python3 Day 2] Chapter 2 Py Components: Numbers, Strings, Variables (2.1)
[Introduction to Python3 Day 4] Chapter 2 Py Components: Numbers, Strings, Variables (2.3.7-2.4)
Bind methods to Python classes and instances
Introduction to Effectiveness Verification Chapter 1 in Python
[Introduction to Python3 Day 7] Chapter 3 Py Tools: Lists, Tuples, Dictionaries, Sets (3.3-3.8)
[Introduction to Python3 Day 5] Chapter 3 Py Tools: Lists, Tuples, Dictionaries, Sets (3.1-3.2.6)
[Introduction to Python3 Day 10] Chapter 5 Py's Cosmetic Box: Modules, Packages, Programs (5.4-5.7)
[Introduction to Python3 Day 9] Chapter 5 Py's Cosmetic Box: Modules, Packages, Programs (5.1-5.4)
[Introduction to Python3 Day 6] Chapter 3 Py tool lists, tuples, dictionaries, sets (3.2.7-3.2.19)
Introduction to effectiveness verification Chapter 3 written in Python
Introduction to Python language
Introduction to OpenCV (python)-(2)
[Introduction to Udemy Python3 + Application] 64. Namespace and Scope
[Python for Hikari] Chapter 09-02 Classes (Creating and instantiating classes)
[Python for Hikari] Chapter 09-01 Classes (Basics of Objects)
Introduction to Effectiveness Verification Chapter 2 Written in Python
[Introduction to Udemy Python3 + Application] 35. Comparison operators and logical operators
The simplest Python memo in Japan (classes and objects)
[Chapter 5] Introduction to Python with 100 knocks of language processing
[Chapter 3] Introduction to Python with 100 knocks of language processing
[Chapter 2] Introduction to Python with 100 knocks of language processing
[Introduction to Udemy Python3 + Application] 68. Import statement and AS
[Technical book] Introduction to data analysis using Python -1 Chapter Introduction-
[Chapter 4] Introduction to Python with 100 knocks of language processing
Introduction to Python Django (2) Win
About Python variables and objects
Introduction to serial communication [Python]
[Introduction to Python] <list> [edit: 2020/02/22]
Introduction to Python (Python version APG4b)
An introduction to Python Programming
Introduction to Python For, While
[Introduction to cx_Oracle] (Part 6) DB and Python data type mapping
[Introduction to Udemy Python3 + Application] 42. for statement, break statement, and continue statement
[Introduction to Udemy Python3 + Application] 39. while statement, continue statement and break statement
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
[Introduction to Udemy Python3 + Application] 50. Positional arguments, keyword arguments, and default arguments
Introduction to Effectiveness Verification Chapters 4 and 5 are written in Python
[Introduction to Python] Combine Nikkei 225 and NY Dow csv data
[Introduction to Udemy Python 3 + Application] 58. Lambda
[Introduction to Udemy Python 3 + Application] 31. Comments
Python 3.6 on Windows ... and to Xamarin.
perl objects and python class part 2.
Python ABC-Abstract Classes and Duck Typing