STUDY/Python

Django | ์ˆ™์ œ | ์กฐ๊ฑด๋ฌธ&๋ฐ˜๋ณต๋ฌธ&class

nicesugi 2022. 5. 27. 13:13

 

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป Github

https://github.com/nicesugi/DjangoClass/tree/main/django/sns


1. ์ƒˆ๋กœ์šด ํŒŒ์ด์ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค. (์ œ์ถœ์„ ์œ„ํ•ด ์œ„์น˜๋ฅผ ์ž˜ ๊ธฐ์–ต ํ•ด ์ฃผ์„ธ์š”)

 

2. project_01.py๋ฅผ ๋งŒ๋“ค๊ณ , ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๋ชจ๋‘ ์ถœ๋ ฅํ•˜๋Š” station_list ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”

๋ฐ์ดํ„ฐ : my_station=['์•ผํƒ‘','๋ชจ๋ž€','์ด๋งค','์„ ๋ฆ‰','ํ•œํ‹ฐ','์™•์‹ญ๋ฆฌ']

 

3. proejct_01.py์— ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜๋ณต๋ฌธ๊ณผ ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ '์„ ๋ฆ‰'๋งŒ ์ถœ๋ ฅ ํ•˜๋Š” station_point ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”

 

4. proejct_02.py์— ๊ฒŒ์‹œ๊ธ€์„ ์ €์žฅํ•˜๋Š” class๋ฅผ ๋งŒ๋“ค๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

ํด๋ž˜์Šค ์•ˆ์— ๋“ค์–ด๊ฐˆ ๋ณ€์ˆ˜๋Š” ( id, title, author, content) ์œผ๋กœ ๋ชจ๋‘ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ €์žฅํ•˜๊ณ , ๊ฒŒ์‹œ๊ธ€ ํ•œ ๊ฐœ๋ฅผ ์ €์žฅํ•ด ๋ณด์„ธ์š”!

 

5. ์ž‘์„ฑํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ œ์ถœ ํ•ด ์ฃผ์„ธ์š”!


my_station=['์•ผํƒ‘','๋ชจ๋ž€','์ด๋งค','์„ ๋ฆ‰','ํ•œํ‹ฐ','์™•์‹ญ๋ฆฌ']

# 1. ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๋ชจ๋‘ ์ถœ๋ ฅํ•˜๋Š” station_list ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”
def station_list():
    for station in my_station :
        print(station)   
station_list()

# 2. ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜๋ณต๋ฌธ๊ณผ ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ '์„ ๋ฆ‰'๋งŒ ์ถœ๋ ฅ ํ•˜๋Š” station_point ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”
def station_point():
    for station in my_station :
        if station == '์„ ๋ฆ‰' :
            print("์„ ๋ฆ‰")
station_point()
# ๋ชจ๋ฒ”๋‹ต์•ˆ์˜ˆ์‹œ : ์ข€ ๋” ์ •ํ™•ํ•˜๊ฒŒ๋Š” ์ธ์ž๊ฐ’์„ ๋„ฃ์–ด์ค˜์•ผํ•จ
def station_list(station_list):
    for station in station_list:
        print(station)

station_list(my_station)
# 3. ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜๋ณต๋ฌธ๊ณผ ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ '์„ ๋ฆ‰'๋งŒ ์ถœ๋ ฅ ํ•˜๋Š” station_point ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”
class article:
    id = ''
    title = ''
    author = ''
    content = ''
    
posting = article()
posting.id = 'django'
posting.title = 'django_1day'
posting.author = 'beginner'
posting.content = 'difficult'
    
print(posting.id)
print(posting.title)
print(posting.author)
print(posting.content)
๋ฐ˜์‘ํ˜•