๐Python
Welcome to Python : ๋ด์ฅ ํจ์
4:Bee
2023. 7. 25. 20:15
728x90
- ํด๋์ค : https://hi-code.tistory.com/123
- ๋ชจ๋ : https://hi-code.tistory.com/124
- ํจํค์ง : https://hi-code.tistory.com/125
- ์์ธ ์ฒ๋ฆฌ : https://hi-code.tistory.com/126
- ๋ด์ฅ ํจ์ : https://hi-code.tistory.com/127
- ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ : https://hi-code.tistory.com/128
- ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ :https://hi-code.tistory.com/129
Title | Code | Console |
abs |
# ์ ๋๊ฐ์ ๋ฆฌํด a = abs(3)
print(a)
a = abs(-3)
print(a)
abs(-1.2)
print(a)
|
3 3 3 |
all |
a = all([1, 2, 3]) # 1,2,3์ด True print(a)
a = all([1, 2, 3, 0]) # 1,2,3์ด True ์ง๋ง 0์ผ๋ก False
print(a)
a = all([]) # ๋น๊ฐ์ False
print(a)
|
True False True |
any |
a = any([1, 2, 3, 0]) # 1,2,3์ด True print(a)
a = any([0, ""]) # 0๊ณผ ""๋ False
print(a)
a = any([]) # ๋น๊ฐ์ False
print(a)
|
True False False |
chr |
# ์ซ์ ๊ฐ์ ์ ๋ ฅ๋ฐ์ ๊ทธ ์ฝ๋์ ํด๋นํ๋ ๋ฌธ์๋ฅผ ๋ฆฌํด a = chr(97)
print(a)
|
a |
dir |
# ๊ฐ์ฒด๊ฐ ์ง๋ ๋ณ์๋ ํจ์๋ฅผ ๋ณด์ฌ์ฃผ๋ ํจ์ print(dir([1, 2, 3]))
print(dir({'1', 'a'}))
|
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__'... |
divmod |
# a,b์ ์ธ์๋ฅผ ๋๋ ๋ชซ๊ณผ ๋๋จธ์ง๋ฅผ ํํ๋ก ๋ฆฌํด print(divmod(7, 3))
|
(2, 1) |
enumerate |
# ๋ฐ์ดํฐ๋ฅผ ์ ๋ ฅ๋ฐ์ ์ธํ ์ค ๊ฐ์ ํฌํจํ๋ ์ด๊ฒจํ ๊ฐ์ฒด for i, name in enumerate(['body', 'foo', 'bar']):
print(i, name)
|
0 body 1 foo 2 bar |
eval |
#๋ฌธ์์ด๋ก ๊ตฌ์ ๋ ํํ์์ ์ ๋ ฅ์ผ๋ก ๋ฐ์ ํด๋น ๋ฌธ์์ด ์คํ print(eval('1 + 2'))
print(eval('divmod(4,3)'))
|
3 (1, 1) |
filter |
#filter๋ฅผ ์ฌ์ฉํ์ง ์์ ์ฝ๋ def positive(l):
result = [] #์์๋ง ๊ฑธ๋ฌ ๋ด์ ์ ์ฅํ ๋ณ์
for i in l:
if i > 0:
result.append(i) #๋ฆฌ์คํธ์ i ์ถ๊ฐ
return result
print(positive([1, -3, 2, 0, -5, 6]))
|
[1, 2, 6] |
def positive(x): return x > 0
print(list(filter(positive, [1, -3, 2, 0, -5, 6])))
|
[1, 2, 6] | |
hex |
a = hex(234) # 16์ง์๋ก ๋ณํ print(a)
|
0xea |
id |
a = 3 print(id(3))
print(id(a))
b = a
print(id(b))
|
2186759766320 2186759766320 2186759766320 |
input |
a = input("Enter : ") b = input()
|
Enter : 123 123 |
int |
a = int('3') print(a)
|
3 |
isinstance |
class Person: pass
a = Person()
print(isinstance(a, Person))
|
True |
len |
a = len("python") print(a)
a = len([1, 2, 3])
print(a)
a = len((1, 'a'))
print(a)
|
6 3 2 |
list |
a = list('python') print(a)
|
['p', 'y', 't', 'h', 'o', 'n'] |
map |
#for๋ฌธ def two_times(numberList):
result = []
for number in numberList:
result.append(number * 2)
return result
result = two_times([1, 2, 3, 4])
print(result)
|
[2, 4, 6, 8] |
# map def two_times(x):
return x*2
result = list(map(two_times, [1, 2, 3, 4]))
print(result)
|
[2, 4, 6, 8] | |
max |
a = max([1, 2, 3]) print(a)
a = max("python")
print(a)
|
3 y |
min |
a = min([1, 2, 3]) print(a)
a = min("python")
print(a)
|
1 h |
oct |
a = oct(34) #8์ง์ ๋ฌธ์์ด๋ก ๋ณ๊ฒฝ print(a)
|
0o42 |
open |
f = open("binary_file", "rb") |
|
ord |
a = ord('a') # ์ ๋์ฝ๋ ์ซ์ ๊ฐ ๋ฆฌํด print(a)
|
97 |
pow |
a = pow(2, 5) #2^5 print(a)
|
32 |
range |
a = list(range(5)) print(a)
|
[0, 1, 2, 3, 4] |
a = list(range(5, 10)) print(a)
|
[5, 6, 7, 8, 9] | |
a = list(range(1, 10, 2)) #์ซ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ 2 print(a)
a = list(range(0, -10, -1)) #์ซ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ -1
print(a)
|
[1, 3, 5, 7, 9] [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] |
|
round |
#2๋ฒ์งธ ๋ฐ์ฌ๋ฆผ print(a)
|
5.68 |
sorted |
a = sorted([3, 1, 2]) print(a)
|
[1, 2, 3] |
str |
a = str(3) print(a)
print(type(a))
|
3 <class 'str'> |
sum |
a = sum([1, 2, 3]) print(a)
|
6 |
tuple |
print(tuple("abc")) print(tuple([1, 2, 3]))
print(tuple((1, 2, 3)))
|
('a', 'b', 'c') (1, 2, 3) (1, 2, 3) |
type |
print(type("abc")) print(type([]))
print(type(open("test", 'w')))
|
<class 'str'> <class 'list'> <class '_io.TextIOWrapper'> |
zip |
zIp = list(zip([1, 2, 3], [4, 5, 6])) print(zIp)
|
[(1, 4), (2, 5), (3, 6)] |
728x90