[๐ŸงจํŒŒ์ด์ฌ ๊ธฐ์ดˆ1] ์ž๋ฃŒํ˜•๊ณผ ์ž๋ฃŒ๊ตฌ์กฐ (์ˆซ์ž, ๋ฌธ์ž์—ด, ๋ถˆ, ๋ณ€์ˆ˜, ๋ฆฌ์ŠคํŠธ, ํŠœํ”Œ, ๋”•์…”๋„ˆ๋ฆฌ, ์ง‘ํ•ฉ)

์•ˆ์ง€์ˆ˜ยท2023๋…„ 1์›” 27์ผ
0

ํŒŒ์ด์ฌ ๊ธฐ์ดˆ

๐ŸŽˆํŒŒ์ด์ฌ๊ณผ C์–ธ์–ด

  • ํŒŒ์ด์ฌ: ์ธํ„ฐํ”„๋ฆฌํ„ฐ ์–ธ์–ด (ํ•œ ์ค„์”ฉ ์ˆ˜ํ–‰-> ๋Š๋ฆผ)
  • C์–ธ์–ด: ์ปดํŒŒ์ผ ์–ธ์–ด(๊ธฐ๊ณ„์–ด๋กœ ์ปดํŒŒ์ผ ํ•˜์—ฌ ์ˆ˜ํ–‰-> ๋น ๋ฆ„)

๐ŸŽˆํŒŒ์ด์ฌ์œผ๋กœ ํ•  ์ˆ˜ ์žˆ๋Š” ์ผ

  • ์‹œ์Šคํ…œ ์œ ํ‹ธ๋ฆฌํ‹ฐ
  • GUI ํ”„๋กœ๊ทธ๋ž˜๋ฐ
  • C/C++ ๊ณผ์˜ ๊ฒฐํ•ฉ
  • ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ (์žฅ์†Œ, flask ํ”„๋ ˆ์ž„ ์›Œํฌ)
  • ์ˆ˜์น˜ ์—ฐ์‚ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
  • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ”„๋กœ๊ทธ๋ž˜๋ฐ
  • ๋ฐ์ดํ„ฐ ๋ถ„์„, ์‚ฌ๋ฌผ ์ธํ„ฐ๋„ท

์ž๋ฃŒํ˜•

๐Ÿ‘‘ ๋ณ€์ˆ˜

: ๊ฐ’์„ ๋‹ด๋Š” ์ƒ์ž
: ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ๊ฒƒ(๊ฐ’์ด ๋‹ด๊ธด ๊ณณ์˜ ์ฃผ์†Œ ๊ฐ€๋ฆฌํ‚ด!!)

๐Ÿ‘‘ ์ˆซ์žํ˜•

  • ์ •์ˆ˜ํ˜•(int), ์‹ค์ˆ˜ํ˜•(float)
  • ์‚ฌ์น™์—ฐ์‚ฐ(**:์ œ๊ณฑ, //:๋ชซ, /:์†Œ์ˆ˜์ , %๋‚˜๋จธ์ง€)

๐Ÿ‘‘ ๋ฌธ์ž์—ดํ˜•

#(", ', """, ''')๋กœ ๋ฌธ์ž์—ด ํ‘œํ˜„ ๊ฐ€๋Šฅ
"Hello"
'Python'
"""python"""
'''hello'''
  • ๋ฌธ์ž์—ด์— ๋”ฐ์˜ดํ‘œ ํฌํ•จ ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ: \', \"
  • ๋ฌธ์ž์—ด ๋”ํ•˜๊ธฐ, ๊ณฑํ•˜๊ธฐ ๊ฐ€๋Šฅ
>> a = 'Life is too short, You need Python'
>>>a[0]
'L'
>>> a[12]
's'
>>> a[-1]
'n' 
>>> a[0:4]
'Life'
  • ์ธ๋ฑ์‹ฑ, ์Šฌ๋ผ์ด์‹ฑ ๊ฐ€๋Šฅ
  • ์Šฌ๋ผ์ด์‹ฑ- a[::]: ์ด์ƒ, ๋ฏธ๋งŒ, ๊ฐ„๊ฒฉ ์˜๋ฏธ(๋น„์–ด ๋†“์œผ๋ฉด ์ฒ˜์Œ๋ถ€ํ„ฐ ์‹œ์ž‘ or ๋๊นŒ์ง€)

๋ฌธ์ž์—ด ํฌ๋งคํŒ…

1. "I ate %d apples" %3
2. "I ate {count} apples".format(count=3)
3. f"I ate {count} apples"

count

: ๋ฌธ์ž์—ด ๊ฐœ์ˆ˜ ์„ธ๊ธฐ

>>> a = "hobby"
>>> a.count('b')
>>> 2

find

: ์œ„์น˜ ์•Œ๋ ค์ฃผ๊ธฐ

>>> a = "favorite"
>>> a.find('f')
>>> 0
  • ์—†์œผ๋ฉด '-1' ์ถœ๋ ฅ!

index

: ์œ„์น˜ ์•Œ๋ ค์ฃผ๊ธฐ(2)

>>> a = "favorite"
>>> a.index('f')
>>> 0

join

: ๋ฌธ์ž์—ด ์‚ฝ์ž…

>>> a = ","
>>> a.join('abcd')
>>> a,b,c,d

lower ๊ณผ upper

: ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊พธ๊ธฐ

>>> a.lower()
>>> a.upper()

strip

: ์–‘์ชฝ ๊ณต๋ฐฑ ์ง€์šฐ๊ธฐ

>>> a = "      hobby"
>>> a.split('a')
>>> hobby

split

: ๋ฌธ์ž์—ด ๋‚˜๋ˆ„๊ธฐ(ํŠน์ • ๋ฌธ์ž์—ด ๊ธฐ์ค€์œผ๋กœ๋„ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์Œ-๊ด„ํ˜ธ์—)

>>> a = "Life is too short"
>>> a.split()
>>> ['Life', 'is', 'too', 'short']

replace

: ๋ฌธ์ž์—ด ๋ฐ”๊พธ๊ธฐ

>>> a = "Life is too short"
>>> a.replace("Life", "Young")

๐Ÿ‘‘ ๋ฆฌ์ŠคํŠธํ˜•[]

: ๋ณ€์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ, ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜์— ํ•œ ๋ฒˆ์— ๊ด€๋ฆฌ(์„œ๋ž์žฅ)

  • ๋ฆฌ์ŠคํŠธ ์•ˆ์— ๋ฆฌ์ŠคํŠธ ๊ฐ€๋Šฅ, ์ž๋ฃŒํ˜• ์„ž์„ ์ˆ˜ ์žˆ์Œ
  • ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ
>>> a = [1, 2, [3, 4]]
>>> a[2][1]
4
  • ์ธ๋ฑ์‹ฑ(์Œ์ˆ˜ ๊ฐ€๋Šฅ-๋’ค๋กœ ๊ฐ€๊ธฐ), ์Šฌ๋ผ์ด์‹ฑ ๊ฐ€๋Šฅ
  • ๋ฆฌ์ŠคํŠธ ๋”ํ•˜๊ธฐ, ๊ณฑํ•˜๊ธฐ(๋ฐ˜๋ณต) ๊ฐ€๋Šฅ

ํ•˜๋‚˜์˜ ๊ฐ’ ์ˆ˜์ •

>>> a = [1, 2, 3]
>>> a[2] = 4
>>> a
[1, 2, 4]

์—ฐ์†๋œ ๋ฒ”์œ„์˜ ๊ฐ’ ์ˆ˜์ •

>>> a = [1, 2, 3]
>>> a[1:2] = [4, 5, 6]
>>> a
[1, 4, 5, 6, 3]

์š”์†Œ ์‚ญ์ œํ•˜๊ธฐ, ์ œ๊ฑฐ

  1. []
>>> a = [1, 2, 3, 4]
>>> a[1:3] = []
>>> a
[1, 4]
  1. del
>>> a = [1, 2, 3]
>>> del a[2]
>>> a
[1, 2]
  1. remove
>>> a = [1, 2, 3, 1, 2, 3]
>>> a.remove(3)
>>> a
[1, 2, 1, 2, 3]  
  • remove: ๊ฐ€์žฅ ์•ž์— ์žˆ๋Š” ๊ฒƒ ํ•˜๋‚˜๋งŒ ์‚ญ์ œ!!

์š”์†Œ ์ถ”๊ฐ€(append)

>>> a = [1, 2, 3]
>>> a.append(4)
>>> a
[1, 2, 3, 4]

๋ฆฌ์ŠคํŠธ ์ •๋ ฌ(sort)

: ํฌ๊ธฐ ์ˆœ, ๊ฐ€๋‚˜๋‹ค ์ˆœ

>>> a = [2, 1, 3]
>>> a.sort()
>>> a
[1, 2, 3]

๋’ค์ง‘๊ธฐ(reverse)

>>> a = [1, 2, 3]
>>> a.reverse()
>>> a
[3, 2, 1]

์œ„์น˜ ๋ฐ˜ํ™˜(index)

>>> a = [1, 2, 3]
>>> a.index(3)
2

์š”์†Œ ์‚ฝ์ž…(insert)

>>> a = [1, 2, 3]
>>> a.insert(0, 4)
>>> a
[4, 1, 2, 3]

์š”์†Œ ๊บผ๋‚ด๊ธฐ(pop)

>>> a = [1, 2, 3]
>>> a.pop()
3
  • pop: ๋งˆ์ง€๋ง‰ ๊บผ ํŠ€์–ด๋‚˜์˜ด

์š”์†Œ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ(count)

>>> a = [1, 2, 3, 3, 3]
>>> a.count(3)
3

๋ฆฌ์ŠคํŠธ ํ™•์žฅ

>>> a = [1, 2, 3]
>>> a.extend([4, 5)
>>> a
[1, 2, 3, 4, 5]

๐Ÿ‘‘ ํŠœํ”Œํ˜•()

  • ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€๋Šฅ(์‚ญ์ œ, ์ˆ˜์ • ๋ถˆ๊ฐ€)
  • ์ธ๋ฑ์‹ฑ(์Œ์ˆ˜ ๊ฐ€๋Šฅ-๋’ค๋กœ ๊ฐ€๊ธฐ), ์Šฌ๋ผ์ด์‹ฑ ๊ฐ€๋Šฅ
  • ๋ฆฌ์ŠคํŠธ ๋”ํ•˜๊ธฐ, ๊ณฑํ•˜๊ธฐ(๋ฐ˜๋ณต) ๊ฐ€๋Šฅ

๐Ÿ‘‘ ๋”•์…”๋„ˆ๋ฆฌํ˜•{key:value}

  • key๊ฐ€ ๋งค์šฐ ์ค‘์š”!!!!
    ์ค‘๋ณต ๋˜์ง€ ์•Š์•„์•ผ ํ•จ!!!

์Œ ์ถ”๊ฐ€ํ•˜๊ธฐ

>>> a = {1: 'a'}
>>> a[2] = 'b'
>>> a
{2: 'b', 1:'a'}

์š”์†Œ ์‚ญ์ œํ•˜๊ธฐ(del)

>>> a = {1: 'a'}
>>> del a[1]
>>> a
{2: 'b'}

์Œ ๋ชจ๋‘ ์‚ญ์ œํ•˜๊ธฐ(clear)

>>> a = {1: 'a'}
>>> a.clear()
>>> a
{}

key ์‚ฌ์šฉํ•ด value ์–ป๊ธฐ([], get)

  1. []
>>> a = {1: 'a'}
>>> a[1]
a
  1. get
>>> a = {1: 'a'}
>>> a.get[1]
a

key ๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค๊ธฐ(keys)

>>> a = {1: 'a', 2:'b'}
>>> a.keys()
dict_keys([1, 2])

value ๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค๊ธฐ(values)

>>> a = {1: 'a', 2:'b'}
>>> a.values()
dict_values(['a', 'b'])

key, value ์Œ ์–ป๊ธฐ(items)

>>> a = {1: 'a', 2:'b'}
>>> a.items()
dict_items([(1, 'a'), (2, 'b')])

key๊ฐ€ ๋”•์„œ๋…€๋ฆฌ ์•ˆ์— ์žˆ๋Š”์ง€ ์กฐ์‚ฌํ•˜๊ธฐ

  • 1 in a

๐Ÿ‘‘ ์ง‘ํ•ฉํ˜• set([]), {}

  • ์ˆœ์„œ ์—†๊ณ , ์ค‘๋ณต ์š”์†Œ ๋ถˆ๊ฐ€!!
    1. set([])
>>> a = set([1,2,3])
>>> a
{1,2,3}
  1. {}
>>> a = {1,2,3}
>>> a
{1,2,3}

๊ต์ง‘ํ•ฉ(&, intersection)

>>> a = set([1,2,3,4,5,6])
>>> b = set([4,5,6,7,8,9])
>>> a & b
{4,5,6}
>>> a.intersection(b)
{4,5,6}

ํ•ฉ์ง‘ํ•ฉ(|, union)

>>> a = set([1,2,3,4,5,6])
>>> b = set([4,5,6,7,8,9])
>>> a | b
{1,2,3,4,5,6,7,8,9}
>>> a.union(b)
{1,2,3,4,5,6,7,8,9}

์ฐจ์ง‘ํ•ฉ(-, difference)

>>> a = set([1,2,3,4,5,6])
>>> b = set([4,5,6,7,8,9])
>>> a - b
{1,2,3}
>>> a.difference(b)
{1,2,3}

๊ฐ’ 1๊ฐœ ์ถ”๊ฐ€ํ•˜๊ธฐ(add)

>>> a = set([1,2,3])
>>> a.add(4)
{1,2,3,4}

๊ฐ’ ์—ฌ๋Ÿฌ ๊ฐœ ์ถ”๊ฐ€ํ•˜๊ธฐ(update)

>>> a = set([1,2,3])
>>> a.update([4,5,6])
{1,2,3,4,5,6}

ํŠน์ • ๊ฐ’ ์ œ๊ฑฐํ•˜๊ธฐ

>>> a = set([1,2,3])
>>> a.remove(2)
{1, 3}

๐Ÿ‘‘ '๋ถˆ'ํ˜•(True, False)

  • ๊ทธ๋ƒฅ ์ž๋ฃŒํ˜• ์•ˆ์— ๊ฐ’ ์—†์œผ๋ฉด ์ฐธ!
  • none ์€ ๊ฑฐ์ง“
profile
์ง€์ˆ˜์˜ ์ทจ์ค€, ๊ฐœ๋ฐœ์ผ๊ธฐ

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