ํ์ด์ฌ ๊ธฐ์ด
์๋ฃํ
: ๊ฐ์ ๋ด๋ ์์
: ๊ฐ์ฒด๋ฅผ ๊ฐ๋ฆฌํค๋ ๊ฒ(๊ฐ์ด ๋ด๊ธด ๊ณณ์ ์ฃผ์ ๊ฐ๋ฆฌํด!!)
#(", ', """, ''')๋ก ๋ฌธ์์ด ํํ ๊ฐ๋ฅ
"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'
1. "I ate %d apples" %3
2. "I ate {count} apples".format(count=3)
3. f"I ate {count} apples"
: ๋ฌธ์์ด ๊ฐ์ ์ธ๊ธฐ
>>> a = "hobby"
>>> a.count('b')
>>> 2
: ์์น ์๋ ค์ฃผ๊ธฐ
>>> a = "favorite"
>>> a.find('f')
>>> 0
: ์์น ์๋ ค์ฃผ๊ธฐ(2)
>>> a = "favorite"
>>> a.index('f')
>>> 0
: ๋ฌธ์์ด ์ฝ์
>>> a = ","
>>> a.join('abcd')
>>> a,b,c,d
: ์๋ฌธ์, ๋๋ฌธ์๋ก ๋ฐ๊พธ๊ธฐ
>>> a.lower()
>>> a.upper()
: ์์ชฝ ๊ณต๋ฐฑ ์ง์ฐ๊ธฐ
>>> a = " hobby"
>>> a.split('a')
>>> hobby
: ๋ฌธ์์ด ๋๋๊ธฐ(ํน์ ๋ฌธ์์ด ๊ธฐ์ค์ผ๋ก๋ ๋๋ ์ ์์-๊ดํธ์)
>>> a = "Life is too short"
>>> a.split()
>>> ['Life', 'is', 'too', 'short']
: ๋ฌธ์์ด ๋ฐ๊พธ๊ธฐ
>>> 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]
>>> a = [1, 2, 3, 4]
>>> a[1:3] = []
>>> a
[1, 4]
>>> a = [1, 2, 3]
>>> del a[2]
>>> a
[1, 2]
>>> a = [1, 2, 3, 1, 2, 3]
>>> a.remove(3)
>>> a
[1, 2, 1, 2, 3]
>>> a = [1, 2, 3]
>>> a.append(4)
>>> a
[1, 2, 3, 4]
: ํฌ๊ธฐ ์, ๊ฐ๋๋ค ์
>>> a = [2, 1, 3]
>>> a.sort()
>>> a
[1, 2, 3]
>>> a = [1, 2, 3]
>>> a.reverse()
>>> a
[3, 2, 1]
>>> a = [1, 2, 3]
>>> a.index(3)
2
>>> a = [1, 2, 3]
>>> a.insert(0, 4)
>>> a
[4, 1, 2, 3]
>>> a = [1, 2, 3]
>>> a.pop()
3
>>> a = [1, 2, 3, 3, 3]
>>> a.count(3)
3
>>> a = [1, 2, 3]
>>> a.extend([4, 5)
>>> a
[1, 2, 3, 4, 5]
>>> a = {1: 'a'}
>>> a[2] = 'b'
>>> a
{2: 'b', 1:'a'}
>>> a = {1: 'a'}
>>> del a[1]
>>> a
{2: 'b'}
>>> a = {1: 'a'}
>>> a.clear()
>>> a
{}
>>> a = {1: 'a'}
>>> a[1]
a
>>> a = {1: 'a'}
>>> a.get[1]
a
>>> a = {1: 'a', 2:'b'}
>>> a.keys()
dict_keys([1, 2])
>>> a = {1: 'a', 2:'b'}
>>> a.values()
dict_values(['a', 'b'])
>>> a = {1: 'a', 2:'b'}
>>> a.items()
dict_items([(1, 'a'), (2, 'b')])
>>> a = set([1,2,3])
>>> a
{1,2,3}
>>> a = {1,2,3}
>>> a
{1,2,3}
>>> 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}
>>> 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}
>>> 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}
>>> a = set([1,2,3])
>>> a.add(4)
{1,2,3,4}
>>> 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}