๐ŸŒท๐Ÿฐ๐Ÿข๐Ÿงกโค๏ธ๐Ÿ’›๐Ÿฅจ๐Ÿ”ฅโœ๏ธโœŒ๏ธ โžก โŒโญ•โ“โ—

ํŒŒ์ด์ฌ ๊ฐ•์˜ ๋ณต์Šต(9/13)๐ŸŒท

  • ํด๋ž˜์Šค
class Cookieframe():
    v2='๋ณ€์ˆ˜๋ฅผ ์•„์˜ˆ ์ง€์ •ํ•จ2'
    def __init__(self,v1):
        print(f'{v1}์ด ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค')
        self.v1 = '๋ณ€์ˆ˜๋ฅผ ์•„์˜ˆ ์ง€์ •ํ•จ'
    def self_variable_print(self):
        print(self.v1)
        print(self.v2)
    def self_variable_call(self):
        self.self_variable_print()
    def not_self_vairable_call(self):
        print('self๊ฐ€ ํ•„์š”์—†์œผ๋ฉด ์•ˆ์จ๋„ ๋œ๋‹ค?')#๊ฐ€ ์•„๋‹Œ๋“ฏ

cookie1 = Cookieframe('cookie1')
#์ด๋ ‡๊ฒŒ ๋ฐ”๋กœ ์ฟ ํ‚คํ”„๋ ˆ์ž„(ํด๋ž˜์Šค)์— ๋“ค์–ด๊ฐ€๋„ ๋จ? ok
#init(๋ฐ”๋กœํ˜ธ์ถœ๋จ)์— ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๋“ค์–ด๊ฐ€์žˆ์œผ๋‹ˆ๊นŒ ๋ฐ”๋กœ ๋„ฃ์–ด์คŒ
cookie1.self_variable_call()
cookie1.not_self_vairable_call()
# print(v2) ์ด๊ฑด ์•ˆ๋จ v2๋Š” ํด๋ž˜์Šค ์•ˆ์—์„œ ! ์ „์—ญ๋ณ€์ˆ˜๋‹ˆ๊นŒ!
  • mutable/immutable
from copy import deepcopy
mutable = ['list is mutable']
immutable = 'i am immutable'

list_ = mutable
list_2 = deepcopy(mutable)
string_ = immutable

list_.append('append sth to list')
string_ += 'i am string~!'

print(mutable)
#['list is mutable', 'append sth to list']
print(list_2)
#['list is mutable']
print(immutable)
#i am immutable
print(list_)
#['list is mutable', 'append sth to list']
print(string_)
#i am immutablei am string~!

#๋ฆฌ์ŠคํŠธ๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ(id)๋ฅผ ๊ณต์œ ํ•˜๊ธฐ๋•Œ๋ฌธ์— 1)mutable 3)list_ ๊ฐ’์ด ๊ฐ™๊ฒŒ ์ถœ๋ ฅ๋œ๋‹ค
#-> c์–ธ์–ด ํฌ์ธํ„ฐ ๊ฐœ๋…๊ณผ ๋™์ผ
#๋งŒ์•ฝ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๊ณ ์‹ถ์ง€ ์•Š๋‹ค๋ฉด 2๊ฐ€์ง€ ๋ฐฉ๋ฒ• ์ค‘ ์„ ํƒ
#1)deepcopy(mutable)(<- from copy import deepcopy)
#2)mutable[::]
#[start:end:step]

#์ŠคํŠธ๋ง์€  ๊ฐ’์ด ๋ณ€๊ฒฝ๋˜๋Š” ์ˆœ๊ฐ„ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๊ฐ€ ๋ณ€๊ฒฝ๋˜์–ด ๋‹ค๋ฅธ ๊ณณ์— ์ €์žฅ๋œ๋‹ค

print(id(mutable))  #4478631168 ์Ž”
print(id(list_2))   #4478631360
print(id(immutable))#4478623536
print(id(list_))    #4478631168 ์Ž”
print(id(string_))  #4478677392

์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜๐ŸŒท

  • ์ž„์˜์˜ ๊ธธ์ด์˜ ๋ฆฌ์ŠคํŠธ ๋งŒ๋“œ๋Š” ๋ฒ• (์งฑ์‰ฌ์›€)
alphabet_occurrence_array = [0] * 26

-> 26๊ฐœ ๊ธธ์ด์˜ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค

  • โญ๏ธ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฌธ์ž์—ด๋กœโญ๏ธ ๋ฐ”๊พธ๊ธฐ
    '๋ฌธ์ž์—ด์‚ฌ์ด์— ๋“ค์–ด๊ฐˆ ๊ฒƒ'.join(๋ฆฌ์ŠคํŠธ)

    - 
profile
looooggi

0๊ฐœ์˜ ๋Œ“๊ธ€

Powered by GraphCDN, the GraphQL CDN