์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
[42] 230227 Ch. 3 ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด๋ฅผ ์ํ ํ์ด์ฌ ๊ธฐ์ด ๋ฐฐ์ฐ๊ธฐ: 5. ํ์ด์ฌ ํด๋์ค์ ๋ชจ๋ [K-๋์งํธ ํธ๋ ์ด๋ 42์ผ] ๋ณธ๋ฌธ
[42] 230227 Ch. 3 ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด๋ฅผ ์ํ ํ์ด์ฌ ๊ธฐ์ด ๋ฐฐ์ฐ๊ธฐ: 5. ํ์ด์ฌ ํด๋์ค์ ๋ชจ๋ [K-๋์งํธ ํธ๋ ์ด๋ 42์ผ]
yjyuwisely 2023. 2. 27. 12:33230227 Mon 42nd class
Ch. 3 ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด๋ฅผ ์ํ ํ์ด์ฌ ๊ธฐ์ด ๋ฐฐ์ฐ๊ธฐ
์ง๋: p. 101 ~ (๊ต์ฌ: IoT ์ฌ๋ฌผ์ธํฐ๋ท์ ์ํ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด 4 ์ ์, ์ ์: ์ต์ฃผํธ , ๊น์ฌ๋ฒ , ์ ๋์ง)
์ฐธ๊ณ ๊ฐ๋ฅ ์ฑ
: ์์ด๋ณด๋ฅผ ์ํ Python: ์ฝ๊ฒ ํ์ด ์ด ๊ธฐ์ด ๋ฌธ๋ฒ๊ณผ ์ค์ต
๊ต์ฌ ์ฝ๋ ๊นํ๋ธ: https://github.com/codingspecialist/RaspberryPi4-Book-Example
๊ต์ฌ ์์ค ๋ฐ PPT: http://jspstudy.co.kr/main/main.jsp
์ ์ ์นดํ: https://cafe.naver.com/metacoding
์ค๋ ๋ฐฐ์ด ๊ฒ ์ค ๊ธฐ์ตํ ๊ฒ์ ์ ๋ฆฌํ๋ค.
์๋ก ์ ๊ฒ ๋ ๊ฒ
When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed.
The __init__() Function
All classes have a function called __init__(), which is always executed when the class is being initiated.
Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created:
์์ )
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36)
print(p1.name)
print(p1.age)
๊ฒฐ๊ณผ)
John
36
์ฐธ๊ณ : https://www.w3schools.com/python/python_classes.asp
Python Requests Module
The requests module allows you to send HTTP requests using Python. The HTTP request returns a Response Object with all the response data (content, encoding, status, etc).
The requests.Response() Object contains the server's response to the HTTP request.
์ฐธ๊ณ : https://www.w3schools.com/python/ref_requests_response.asp
Ch. 3 ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด๋ฅผ ์ํ ํ์ด์ฌ ๊ธฐ์ด ๋ฐฐ์ฐ๊ธฐ
์ฑ ์ ๋ชฉ์ฐจ
01 _ ํ์ด์ฌ ์์ํ๊ธฐ
01-1 ํ์ด์ฌ ๊ฐ์
01-2 ํ์ด์ฌ Windows ์ค์นํ๊ธฐ
01-3 ํ์ด์ฌ์ ์ฃผ์
02 _ ํ์ด์ฌ ์๋ฃํ
02-1 ์ซ์ํ
02-2 ๋ฌธ์ํ
02-3 ๋ฆฌ์คํธ
02-4 ํํ
02-5 ๋์ ๋๋ฆฌ
03 _ ํ์ด์ฌ ์ ์ด๋ฌธ
03-1 if๋ฌธ
03-2 for๋ฌธ
03-3 whie๋ฌธ
03-4 break๋ฌธ
04 _ ํ์ด์ฌ ํจ์ ์ฌ์ฉ๋ฒ
04-1 ํจ์ ์ ์ธํ๊ธฐ
04-2 ํจ์ ์ธ์ ์ฌ์ฉํ๊ธฐ
05 _ ํ์ด์ฌ ํด๋์ค์ ๋ชจ๋
05-1 ํด๋์ค
05-2 ๋ชจ๋
05-3 ๋ผ์ด๋ธ๋ฌ๋ฆฌ
5 ํ์ด์ฌ ํด๋์ค์ ๋ชจ๋ p. 101
5.1 ํด๋์ค
ํด๋์ค
class A{
์์ฑ
์์ฑ์(๋ฉ์๋์ ์ผ์ข
)
๋ฉ์๋(๊ธฐ๋ฅ)
}
๊ฐ์ฒด๋ฅผ ์ ์ํ๋ ๋ฐ์ดํฐ(์์ฑ)์ ์ด๋ฅผ ํ์ฉํ๋ ๊ธฐ๋ฅ(๋ฉ์๋)
ํด๋์ค(class)๋ ํ๋ก๊ทธ๋๋ฐ ๊ณผ์ ์์ ๊ฐ์ฒด๋ฅผ ์ ์ํ๋ ๋ฐ์ดํฐ์ ์ด๋ฅผ ํ์ฉํ๋ ๊ธฐ๋ฅ์ ๊ฐ์ง ์ ์๋ ๊ตฌ์กฐ๋ฅผ ์๋ฏธํ๋ค.
๊ฐ ํด๋์ค๋ ๊ฐ์ฒด์ ์ํ๋ฅผ ์ ์ํ ์ ์๋ ์์ฑ(attributes)๊ณผ ๊ฐ์ฒด์ ๊ธฐ๋ฅ์ ์ ์ํ๋ ๋ฉ์๋(methods)๋ฅผ ๊ฐ์ง ์ ์๋ ๊ตฌ์กฐ์ด๋ค.
์์ 1) ๊ฐ์ฒด์ ์์ฑ๊ณผ ๊ฐ์ฒด์ ๊ธฐ๋ฅ์ธ ๋ฉ์๋๊ฐ ์๋ ํด๋์ค๋ฅผ ์ ์ธํ๊ณ ๊ทธ ํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค.
์ง์ญ ๋ณ์์ ์์น๋ ์๊ด์๋ค.
์ง์ญ๋ณ์ ์์ global ํค์๋๊ฐ ์์ผ๋ฉด ์ ์ญ๋ณ์
class AutoMobile:
#์์ฑ
name = "" #์๋ฃํ์ด ๋ฌธ์์ด์ธ name ๋ณ์ ์ ์ธ (์ง์ญ๋ณ์)
velocity = 0 #์๋ฃํ์ด ์ ์์ธ velocity ๋ณ์ ์ ์ธ (์ง์ญ๋ณ์)
# global a = 10 # ์ง์ญ๋ณ์ ์์ global ํค์๋๊ฐ ์์ผ๋ฉด ์ ์ญ๋ณ์
# #์์ฑ์(๋ฉ์๋์ ์ผ์ข
) (๋งค๊ฐ๋ณ์ ์์)
def __init__(self):
self.name = ""
self.velocity = 0
#์์ฑ์ (๋งค๊ฐ๋ณ์ ์์)
# def __init__(self, name, velocity): #๋งค๊ฐ๋ณ์ 2๊ฐ์ธ ์์ฑ์
# self.name = name
# self.velocity = velocity
#๋ฉ์๋
def velocityPlus(self):
self.velocity = self.velocity + 1
print("์๋๋ %d ์
๋๋ค." % self.velocity)
def velocityDw(self):
self.velocity = self.velocity -1
if self.velocity < 0:
self.velocity = 0
print("์๋๋ %d ์
๋๋ค." % self.velocity)
ac = AutoMobile() #AutoMobile ํด๋์ค ๊ฐ์ฒด ์์ฑ
ac.velocityPlus() #velocityPlus() ๋ฉ์๋ ํธ์ถ (0+1=1) ์๋๋ 1 ์
๋๋ค.
ac.velocity = 20 #๊ฐ์ฒด ์์ฑ์ ๊ฐ์ ๋์
: velocity๋ณ์์ 20 ๋์
ac.velocityDw() #velocityDw() ๋ฉ์๋ ํธ์ถ (20-1=19) ์๋๋ 19์
๋๋ค.
๊ฒฐ๊ณผ)
์๋๋ 1 ์
๋๋ค.
์๋๋ 19 ์
๋๋ค
์์ 2) ๊ฐ์ฒด ์์ฑ์ ํธ์ถ๋๋ ํน์ ๋ด์ฅ ํจ์์ธ __init__()๊ณผ self ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ค.
All classes have a function called __init__(), which is always executed when the class is being initiated.
class AutoMobile:
#์์ฑ
name = "" #์๋ฃํ์ด ๋ฌธ์์ด์ธ name ๋ณ์ ์ ์ธ
velocity = 0 #์๋ฃํ์ด ์ ์์ธ velocity ๋ณ์ ์ ์ธ
#์์ฑ์
def __init__(self, str):#๊ฐ์ฒด ์์ฑ ์ ํธ์ถ๋๋ ํน์ ๋ด์ฅ ํจ์, self๋ ๊ฐ์ฒด ์์ ์ ์๋ฏธ
self.name = str #str ๋ฌธ์์ด์ 02๋ผ์ธ์ name์ ๋์
#๋ฉ์๋
def velocityPlus(self):
self.velocity = self.velocity + 1
def velocityDw(self):
self.velocity = self.velocity -1
if self.velocity < 0:
self.velocity = 0
ac = AutoMobile("์๋ํ") #๋ฌธ์์ด์ ๋งค๊ฐ๋ณ์๋ก ๊ฐ์ฒด๋ฅผ ์์ฑ
ac.velocity = 20
ac.velocityPlus()
print(ac.name+"์ ์๋๋ %d ์
๋๋ค." % ac.velocity)
์๋๋ ์์ ๊ฐ์ ์๋ฐ์ ์ฝ๋์ด๋ค.
์๋ฐ์์์ this๋ ํ์ด์ฌ์ self์ด๋ค.
class AutoMobile{
//์์ฑ
String name;
int velocity;
//์์ฑ์ (๋งค๊ฐ๋ณ์ ์์)
AutoMobile(){}
//์์ฑ์ (๋งค๊ฐ๋ณ์ ์์)
AutoMobile(name, velocity){
this.name = name;
this.velocity = velocity;
}
//๋ฉ์๋
void velocityPlus(){
velocity += 1; //velocity = velocity + 1
void velocityDw(){
velocity -= 1; //velocity = velocity - 1
if (velocity < 0){
velocity = 0;
}
printf("์๋๋ %d ์
๋๋ค.", velocity)
}
}
class AutoMobileTest{
public static void main(String[] args){
//๊ฐ์ฒด(AutoMobile ํด๋์ค instance)
Automobile ac = AutoMobile();
}
}
๊ฒฐ๊ณผ)
์๋ํ์ ์๋๋ 21 ์
๋๋ค.
5.2 ๋ชจ๋
ํจ์์ ๋ชจ์์ง
๋ณ์๋ ํจ์ ๋๋ ํด๋์ค๋ฅผ ๋ชจ์ ๋์ ํ์ด์ฌ ํ์ผ
๋ชจ๋์ ๋ฏธ๋ฆฌ ์์ฑ๋ ํจ์ ์ฝ๋๋ฅผ ๋ชจ์ ๋์ ํ์ด์ฌ ํ์ผ์ด๋ค. ๋ชจ๋ํ๋ฅผ ํตํด์ ๋ฏธ๋ฆฌ ๊ตฌํ๋ ๋ค์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ ์ ์๋ค. ๋๋ ์ง์ ๋ชจ๋์ ๊ฐ๋ฐํ ์๋ ์์ผ๋ฉฐ ํ์ด์ฌ ๊ฐ๋ฐํ๊ฒฝ์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณตํ๊ณ ์๋ ๋ค์ํ ํ์ด์ฌ ๋ชจ๋์ ์ฌ์ฉํ ์ ์๋ค.
์ฐธ๊ณ : https://wikidocs.net/77
ํ์ด์ฌ์์ ๋ชจ๋(module)์ด๋ ํ๋์ ํ์ด์ฌ ํ์ผ(.py ํ์ผ)์ ์๋ฏธํฉ๋๋ค.
๋ํ ํจํค์ง(package)๋ ์ด๋ฌํ ๋ชจ๋๋ค์ด ์ฌ๋ฌ ๊ฐ ๋ชจ์ฌ์๋ ๊ฒ์ ๊ฐ๋ฆฌํต๋๋ค.
์์ 1) ๊ฐ๋จํ ์ผ๋ฐ ํจ์ ์ธ ๊ฐ๋ฅผ ํฌํจํ๊ณ ์๋ ๋ชจ๋์ ๋ง๋ ๋ค.
#ํ๋์ ๋ชจ๋์ 3๊ฐ์ ํจ์๋ฅผ ์ ์ธ
def mydef01(): #ํจ์ ์ ์ธ
print("์ผ๋ฐ ํจ์์
๋๋ค.")
def mydef02(n):
print(n * n * 3.14159)
def mydef03(n, m): #๋งค๊ฐ๋ณ์ ์๋ ํจ์ ์ ์ธ
print(n * m)
์์ 2) ์ผ๋ฐ ํจ์ ๋ ๊ฐ๋ฅผ ์ ์ธํ module01.py ๋ชจ๋์ ์ฌ์ฉํ ์์ ์ด๋ค.
ํ์ผ ์ด๋ฆ์ .py๋ก ํด์ผ ์ ์์ ์ผ๋ก ์๋ํ๋ค.
import module01 #์ฌ์ฉ์ ์ ์ ํจ์ ๊ฐ์ ธ์จ๋ค.
import sys #๋ด์ฅ ํจ์ ๊ฐ์ ธ์จ๋ค.
import math
#module01ํ์ผ์ mydef01ํจ์ ํธ์ถ
module01.mydef01()
#module01ํ์ผ์ mydef02ํจ์ ํธ์ถ
module01.mydef02(5)
#module01ํ์ผ์ mydef03ํจ์ ํธ์ถ
module01.mydef03(10,20)
print("---------------------")
print(sys.builtin_module_names)
print(round(3.14))
๊ฒฐ๊ณผ)
(,) ํํ ํ์์ผ๋ก ๋ณ๊ฒฝ ๋ถ๊ฐ๋ฅ์ด๋ค.
์ผ๋ฐ ํจ์์
๋๋ค.
78.53975
200
---------------------
('_abc', '_ast', '_bisect', '_blake2', '_codecs', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_collections', '_contextvars', '_csv', '_datetime', '_functools', '_heapq', '_imp', '_io', '_json', '_locale', '_lsprof', '_md5', '_multibytecodec', '_opcode', '_operator', '_pickle', '_random', '_sha1', '_sha256', '_sha3', '_sha512', '_signal', '_sre', '_stat', '_statistics', '_string', '_struct', '_symtable', '_thread', '_tokenize', '_tracemalloc', '_typing', '_warnings', '_weakref', '_winapi', '_xxsubinterpreters', 'array', 'atexit', 'audioop', 'binascii', 'builtins', 'cmath', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal',
'math', 'mmap', 'msvcrt', 'nt', 'sys', 'time', 'winreg', 'xxsubtype', 'zlib')
3
5.3 ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๋ณ์๋ ํจ์ ๋๋ ํด๋์ค ๋ฑ์ ๋ฏธ๋ฆฌ ๋ง๋ค์ด์ ๋ชจ์ ๋์ ๊ฒ
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ชจ๋๊ณผ ๋ชจ๋์ ๋ชจ์ฌ์ ๋ง๋ ๊ฐ๋
์ด๋ค. ํ์ด์ฌ์ ์ค์นํ๋ฉด ์๋์ ์ผ๋ก ๋ด์ฅ๋ชจ๋์ ์ ๊ณตํ์ง๋ง ์ธ๋ถ์์ ์ ๊ณต๋๋ ๋ชจ๋๋ ์กด์ฌํ๋ค. ์ธ๋ถ์์ ์ ๊ณต๋๋ ๋ชจ๋์ ์ฌ์ฉํ๋ ค๋ฉด ๋ผ์ด๋ธ๋ฒ๋ฆฌ ์ค์น๋ฅผ ํด์ผ ํ๋ค.
cmd์์ ์๋ ๋ช
๋ น์ด๋ฅผ ์
๋ ฅํ์ฌ requests ์ค์น๋ฅผ ์งํํ๋ค.
TERMINAL์ ์ ๋ ฅํ๋ค.
pip install ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ช
requests๋ผ๋ ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํ๋ค. requests๋ ์น์ ๋ํด ์์ฒญ์ ํด์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋ ์ญํ ์ ํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค.
pip3 install requests
์์ ) requests๋ฅผ ์ฌ์ฉํ์ฌ ์ง์ ํ url์ ์์ฒญ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ์์ ์ด๋ค.
ํฌ๋กค๋ง: ๊ฐ์ธ ํน์ ๋จ์ฒด์์ ํ์ํ ๋ฐ์ดํฐ๊ฐ ์๋ ์น(Web)ํ์ด์ง์ ๊ตฌ์กฐ๋ฅผ ๋ถ์ํ๊ณ ํ์
ํ์ฌ ๊ธ์ด์ต๋๋ค. ์ฌ๊ธฐ์ ๊ธ์ด์จ๋ค๋ ์๋ฏธ๋ ๋ชจ๋ ๊ทธ๋๋ก ๊ฐ์ ธ์ค๋ ๊ฒ์ ๋งํฉ๋๋ค.
import requests
url = 'http://www.naver.com/'
movie = requests.get(url)
print(movie.text)
๊ฒฐ๊ณผ)
<!doctype html> <html lang="ko" data-dark="false"> <head> <meta charset="utf-8"> <title>NAVER</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=1190"> <meta name="apple-mobile-web-app-title" content="NAVER"/> <meta name="robots" content="index,nofollow"/> <meta name="description" content="๋ค
์ด๋ฒ ๋ฉ์ธ์์ ๋ค์ํ ์ ๋ณด์ ์ ์ฉํ ์ปจํ
์ธ ๋ฅผ ๋ง๋ ๋ณด์ธ์"/> <meta property="og:title" content="๋ค์ด๋ฒ"> <meta property="og:url" content="https://www.naver.com/"> <meta property="og:image" content="https://s.pstatic.net/static/www/mobile/edit/2016/0705/mobile_212852414260.png"> <meta property="og:description" content="๋ค์ด๋ฒ ๋ฉ์ธ์์ ๋ค์ํ ์ ๋ณด์ ์ ์ฉํ ์ปจํ
์ธ ๋ฅผ ๋ง
๋ ๋ณด์ธ์"/> <meta name="twitter:card" content="summary"> <meta name="twitter:title" content=""> <meta name="twitter:url"
content="https://www.naver.com/"> <meta name="twitter:image"
content="https://s.pstatic.net/static/www/mobile/edit/2016/0705/mobile_212852414260.png"> <meta name="twitter:description" content="๋ค์ด๋ฒ ๋ฉ์ธ์์ ๋ค์ํ ์ ๋ณด์ ์ ์ฉํ ์ปจํ
์ธ ๋ฅผ ๋ง๋
๋ณด์ธ์"/> <link rel="stylesheet" href="https://pm.pstatic.net/dist/css/nmain.20221110.css"> <link rel="stylesheet" href="https://ssl.pstatic.net/sstatic/search/pc/css/sp_autocomplete_220526.css"> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?1"/> <link rel="apple-touch-icon" sizes="114x114" href="https://s.pstatic.net/static/www/u/2014/0328/mma_204243574.png"/> <link rel="apple-touch-icon" href="https://s.pstatic.net/static/www/u/2014/0328/mma_20432863.png"/> <script>window.nmain=window.nmain||{},window.nmain.supportFlicking=!1;var nsc="navertop.v4",ua=navigator.userAgent,useIeJSFlag="1";window.nmain.isIE="0"===useIeJSFlag,document.getElementsByTagName("html")[0].setAttribute("data-useragent",ua),window.nmain.isIE&&(Object.create=function(n){function e(){}return e.prototype=n,new e})</script> <script>var darkmode= false;window.naver_corp_da=window.naver_corp_da||{main:{}},window.naver_corp_da.main=window.naver_corp_da.main||{},window.naver_corp_da.main.darkmode=darkmode,window.gladsdk=window.gladsdk||{cmd:[]},window.gladsdk.cmd.push((function(){window.gladsdk.setHostMeta("theme",darkmode?"dark":"light")})),window.ndpsdk=window.ndpsdk||{cmd:[],polyfill:{cmd:[]}},window.ndpsdk.cmd.push((function(){window.ndpsdk.setHostMeta("theme",darkmode?"dark":"light")}))</script> <script async src="https://ssl.pstatic.net/tveta/libs/glad/prod/gfp-core.js"></script> <script
async src="https://ssl.pstatic.net/tveta/libs/ndpsdk/prod/ndp-loader.js"></script> <script> window.nmain.gv = { isLogin: false,
useId: null, daInfo: {"BEAUTY":{"menu":"BEAUTY","childMenu":"","adType":"singleDom","multiDomAdUrl":"","multiDomUnit":"","infoList":[{"adposId":"1000163","singleDomAdUrl":"https://siape.veta.naver.com/fxshow","param":{"da_dom_id":"p_main_beauty_1","tb":"BEAUTY_1","unit":"SU10595","calp":"-"},"type":{"position":"abs","positionIndex":4,"subject":"contents"},"dom":null},{"adposId":"1000164","singleDomAdUrl":"https://siape.veta.naver.com/fxshow","param":{"da_dom_id":"p_main_beauty_2","tb":"BEAUTY_1","unit":"SU10596","calp":"-"},"type":{"position":"abs","positionIndex":8,"subject":"contents"},"dom":null}]},"LIVING":{"menu":"LIVING","childMenu":"","adType":"singleDom","multiDomAdUrl":"","multiDomUnit":"","infoList":[{"adposId":"1000183","singleDomAdUrl":"https://siape.veta.naver.com/fxshow","param":{"da_dom_id":"p_main_living_1","tb":"LIVING_1","unit":"SU10597","calp":"-"},"type":{"position":"abs","positionIndex":4,"subject":"contents"},"dom":null},{"adposId":"1000184","singleDomAdUrl":"https://siape.veta.naver.com/fxshow","param":{"da_dom_id":"p_main_living_2","tb":"LIVING_1","unit":"SU10606","calp":"-"},"type":{"position":"abs","positionIndex":8,"subject":"contents"},"dom":null}]},"LIVINGHOME":{"menu":"LIVINGHOME","childMenu":"","adType":"singleDom","multiDomAdUrl":"","multiDomUnit":"","infoList":[{"adposId":"1000185","singleDomAdUrl":"https://siape.veta.naver.com/fxshow","param":{"da_dom_id":"p_main_livinghome_1","tb":"LIVINGHOME_1","unit":"SU10571","calp":"-"},"type":{"position":"abs","positionIndex":4,"subject":"contents"},"dom":null},{"adposId":"1000186","singleDomAdUrl":"https://siape.veta.naver.com/fxshow","param":{"da_dom_id":"p_main_livinghome_2","tb":"LIVINGHOME_1","unit":"SU10572","calp":"-"},"type":{"position":"abs","positionIndex":8,"subject":"contents"},"dom":null}]}},
svt: 20230227113346,
}; </script> <script> window.nmain.newsstand = {
rcode: '10140106',
newsCastSubsInfo: '',
newsStandSubsInfo: ''
};
window.etc = { };
window.svr = "<!--aweb21-->"; </script> <script src="https://ssl.pstatic.net/tveta/libs/assets/js/pc/main/min/pc.veta.core.min.js" defer="defer"></script> <script src="https://pm.pstatic.net/dist/js/external.2961eaa5.js?o=www" type="text/javascript" crossorigin="anonymous" defer="defer"></script> <script src="https://pm.pstatic.net/dist/js/preload.5fe99fda.js?o=www" type="text/javascript" crossorigin="anonymous" defer="defer"></script> <script src="https://pm.pstatic.net/dist/js/polyfill.f3c68d2d.js?o=www" type="text/javascript" crossorigin="anonymous" defer="defer"></script> <script src="https://pm.pstatic.net/dist/js/vendors~more~nmain~notice~search~sidebar_notice.40da85e0.js?o=www" type="text/javascript" crossorigin="anonymous" defer="defer"></script> <script src="https://pm.pstatic.net/dist/js/search.c0c3b1c5.js?o=www" type="text/javascript" crossorigin="anonymous" defer="defer"></script> <script src="https://pm.pstatic.net/dist/js/vendors~more~nmain~sidebar_notice.7aad5e27.js?o=www" type="text/javascript" crossorigin="anonymous" defer="defer"></script> <script src="https://pm.pstatic.net/dist/js/nmain.e31af4db.js?o=www" type="text/javascript" crossorigin="anonymous" defer="defer"></script>
<style>:root{color-scheme:light}#_nx_kbd .setkorhelp a{display:none}</style> </head> <body> <div id="u_skip"> <a href="#newsstand"><span>๋ด์ค์คํ ๋ ๋ฐ๋ก๊ฐ๊ธฐ</span></a> <a href="#themecast"><span>์ฃผ์ ๋ณ์บ์คํธ ๋ฐ๋ก๊ฐ๊ธฐ</span></a> <a href="#timesquare"><span>ํ์์คํ์ด ๋ฐ๋ก๊ฐ๊ธฐ</span></a> <a href="#shopcast"><span>์ผํ์บ์คํธ ๋ฐ๋ก๊ฐ๊ธฐ</span></a> <a href="#account"><span>๋ก๊ทธ์ธ ๋ฐ๋ก๊ฐ๊ธฐ</span></a> </div> <div id="wrap">
<style>._1syGnXOL{padding-right:18px;font-size:14px;line-height:0;letter-spacing:-.25px;color:#000}._1syGnXOL span,._1syGnXOL strong{line-height:49px}._1syGnXOL:before{display:inline-block;content:"";vertical-align:top;background-image:url(https://static-whale.pstatic.net/main/sprite-20220527@2x.png);background-repeat:no-repeat;background-size:141px 112px;width:18px;height:18px;margin:16px 8px 0 0;background-position:-98px
0}[data-useragent*="MSIE 8"] ._1syGnXOL:before{background-image:url(https://static-whale.pstatic.net/main/sprite-20220527.png)}._1syGnXOL._3dsvmZg2:before{background-position:-47px -85px}._1syGnXOL._1NBFx1WK:before{width:20px;height:20px;margin:15px 8px 0 0;background-position:-21px -89px}._1syGnXOL._2mcQEKCd:before{width:22px;height:22px;margin:14px 7px 0 0;background-position:-47px -63px}._1syGnXOL._36slsKuJ:before{width:21px;height:49px;margin:0 14px 0 0;background-position:0 -63px}._1syGnXOL._3qlJVWzR:before{width:24px;height:49px;margin:0 10px 0 0;background-position:-117px 0}._1syGnXOL._3VkgqBXB:before{width:26px;height:49px;margin:0 10px 0 0;background-position:-116px -54px}._1syGnXOL._3di88A4c{padding-right:12px;font-size:17px}._1syGnXOL._3di88A4c:before{content:none}._1syGnXOL ._19K4X1CD{text-decoration:underline}._2aeXMlrb{display:inline-block;position:relative;font-size:12px;height:49px;width:78px;text-decoration:none;color:#fff;font-weight:700;letter-spacing:-.5px;vertical-align:top}._2aeXMlrb span{text-align:center;margin:9px 0;height:31px;display:block;line-height:31px;border-radius:15px}._2aeXMlrb span:before{display:inline-block;content:"";vertical-align:top;background-image:url(https://static-whale.pstatic.net/main/sprite-20220527@2x.png);background-repeat:no-repeat;background-size:141px 112px}[data-useragent*="MSIE 8"] ._2aeXMlrb span:before{background-image:url(https://static-whale.pstatic.net/main/sprite-20220527.png)}._2aeXMlrb.BMgpjddw{font-size:11px;width:94px}._2aeXMlrb.BMgpjddw span:before{margin:9px 3px 0 0;width:17px;height:13px;background-position:-89px -63px}._3h-N8T9V{position:absolute;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0)}._1KncATpM{display:inline-block;content:"";vertical-align:top;background-image:url(https://static-whale.pstatic.net/main/sprite-20220527@2x.png);background-repeat:no-repeat;background-size:141px 112px;margin-top:14px;float:left;width:98px;height:21px;background-position:0 -21px}[data-useragent*="MSIE 8"] ._1KncATpM{background-image:url(https://static-whale.pstatic.net/main/sprite-20220527.png)}._1KncATpM._2v3uxv2x{background-position:0 0}._1KncATpM._1yl_Ow6o{background-position:0 -42px}._20PYt6lT{font-size:11px;height:49px;cursor:pointer;position:absolute;top:0;right:0;color:#666;opacity:.7}._20PYt6lT:after{width:15px;height:15px;margin-left:4px;background-position:-98px -33px;display:inline-block;content:"";vertical-align:top;background-image:url(https://static-whale.pstatic.net/main/sprite-20220527@2x.png);background-repeat:no-repeat;background-size:141px 112px}[data-useragent*="MSIE 8"] ._20PYt6lT:after{background-image:url(https://static-whale.pstatic.net/main/sprite-20220527.png)}._20PYt6lT._39oMCV2N:after{background-position:-98px -18px}._20PYt6lT._3MOWOORv{color:#c3c2c2}._20PYt6lT._3MOWOORv:after{background-position:-80px -85px}._20PYt6lT._3wm5EzmJ{color:#fff}._20PYt6lT._3wm5EzmJ:after{background-position:-65px -85px}._1hiMWemA{height:49px}._1hiMWemA .tY_u8r23{position:relative;width:1130px;margin:0 auto}._1hiMWemA .tY_u8r23 a{text-decoration:none}._1hiMWemA._23U_6TM_{position:relative}._1hiMWemA._23U_6TM_:after{position:absolute;z-index:1;content:"";display:block;width:100%;height:1px;bottom:0;background-color:rgba(0,0,0,.050980392156862744)}</style>
<div
id="NM_TOP_BANNER"
data-clk-prefix="top"
class="_1hiMWemA"
style="background-color: #fff7e1"
>
<div class="tY_u8r23">
<a
class="_3h-N8T9V"
href="https://whale.naver.com/ko/details/security/&wpid=RydDy7"
data-clk="dropbanner1a"
></a
><span
class="_1
๋ฌธ์ ํ์ด๋ณด๊ธฐ)
Q1. ํด๋์ค, ๊ฐ์ฒด, ์ธ์คํด์ค์ ๋ํด์ ์ ๋ฆฌํด๋ณธ๋ค.
- ํด๋์ค class [1์ฅ 37์ชฝ] ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ ์ํ ํ๋์ ๋ฉ์๋๊ฐ ์ ์๋ ๊ฒ. ๊ฐ์ฒด์ ์ค๊ณ๋์ ํด๋นํ๋ค.
- ๊ฐ์ฒด object [6์ฅ 212์ชฝ] ๋ฌผ๋ฆฌ์ ์ผ๋ก ์กด์ฌํ๊ฑฐ๋ ์ถ์์ ์ผ๋ก ์๊ฐํ ์ ์๋ ๊ฒ ์ค์์ ์์ ์ ์์ฑ์ ๊ฐ์ง๊ณ ์๊ณ ๋ค๋ฅธ ๊ฒ๊ณผ ์๋ณ ๊ฐ๋ฅํ ๊ฒ์ ๋งํจ. ex) ์๋์ฐจ, ์์ ๊ฑฐ, ์ฑ
, ์ฌ๋ / ํ๊ณผ, ๊ฐ์, ์ฃผ๋ฌธ ๋ฑ...
- ์ธ์คํด์ค instance [6์ฅ 215์ชฝ] ํด๋์ค๋ก๋ถํฐ ๋ง๋ค์ด์ง ๊ฐ์ฒด
- ํด๋์ค : ๊ฐ์ฒด๋ฅผ ๊ตฌํํ๊ธฐ ์ํ ํ, ์ฐ๊ด๋์ด ์๋ ๋ณ์์ ๋ฉ์๋์ ์งํฉ
- ๊ฐ์ฒด : ์ํํธ์จ์ด ์ธ๊ณ์ ๊ตฌํํ ๋์
- ํด๋์ค: ์ค๊ณ๋๊ฐ ํด๋์ค(class)์ด๋ค. ํด๋์ค์๋ ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ ์ํ ํ๋์ ๋ฉ์๋๊ฐ ์ ์๋์ด ์๋ค.
ํด๋์ค๋ฅผ ์ธ์คํด์คํํ๋ฉด ๊ฐ์ฒด์ด๋ค.
- ๊ฐ์ฒด: ์์ฑ๊ณผ ๋์์ ๊ฐ์ง
- ์ธ์คํด์ค: ํด๋์ค๋ก๋ถํฐ ๋ง๋ค์ด์ง ๊ฐ์ฒด
class A: #ํด๋์ค
pass
# ์ธ์คํด์ค
#ํด๋์ค---------->๊ฐ์ฒด
a = A() #๊ฐ์ฒด
Q2. ์ฌ๋ (Human) ํด๋์ค์ "์์ ์์ "๋ฅผ ์ถ๋ ฅํ๋ ์์ฑ์๋ฅผ ์ถ๊ฐํ๋ค.
areum = Human()
์์ ์์
class Human:
#์์ฑ(๋ณ์)
#์์ฑ์(์ด๊ธฐํํจ์)
def __init__(self):
print("์์ ์์ ")
#ํจ์(๋ฉ์๋)
def __init__(self,a):
print(a)
Human("์์ ์์ ")
Q3. ์ฌ๋ (Human) ํด๋์ค์ (์ด๋ฆ, ๋์ด, ์ฑ๋ณ)์ ๋ฐ๋ ์์ฑ์๋ฅผ ์ถ๊ฐํ์ธ์. (=์์ฑ์ ์ ์ธ ๋ง๋์์ค.)
areum = Human("์๋ฆ", 25, "์ฌ์") <-- ์์ฑ์ ํธ์ถ
class Human:
#์์ฑ
name =""
age = 0
gender =""
#์์ฑ์
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
areum = Human("์๋ฆ", 25, "์ฌ์")
Q4. 3๋ฒ์์ ์์ฑํ ์ธ์คํด์ค์ ์ด๋ฆ, ๋์ด, ์ฑ๋ณ์ ์ถ๋ ฅํ์ธ์.
์ด๋ฆ: ์กฐ์๋ฆ, ๋์ด: 25, ์ฑ๋ณ: ์ฌ์
์กฐ์๋ฆ
25
์ฌ์
์ฝ๋)
class Human:
#์์ฑ(๋ณ์)
name =""
age = 0
gender =""
#์์ฑ์(์ด๊ธฐํํจ์)
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
#ํจ์(๋ฉ์๋)
areum = Human("์๋ฆ", 25, "์ฌ์")
print(areum.name)
print(areum.age)
print(areum.gender)
๊ฒฐ๊ณผ)
์๋ฆ
25
์ฌ์
Q5. ์ฌ๋(Human) ํด๋์ค์์ ์ด๋ฆ, ๋์ด, ์ฑ๋ณ์ ์ถ๋ ฅํ๋ who() ๋ฉ์๋๋ฅผ ์ถ๊ฐํ์ธ์.
areum.who()
์ด๋ฆ: ์กฐ์๋ฆ, ๋์ด: 25, ์ฑ๋ณ: ์ฌ์
class Human:
#์์ฑ
name =""
age = 0
gender =""
#์์ฑ์
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
#๋ฉ์๋
def who(self):
print("์ด๋ฆ : %s, ๋์ด : %d, ์ฑ๋ณ : %s" % (self.name,self.age,self.gender))
# print("์ด๋ฆ: %s, " %areum.name
# +"๋์ด: %d, " %areum.age
# +"์ฑ๋ณ: %s " %areum.gender)
areum = Human("์๋ฆ", 25, "์ฌ์")
areum.name = "์กฐ์๋ฆ"
areum.age = 25
areum.gender = "์ฌ์"
areum.who()
๊ฒฐ๊ณผ)
์ด๋ฆ: ์กฐ์๋ฆ ๋์ด: 25 ์ฑ๋ณ: ์ฌ์