파이썬 기본문법
파이썬 기본문법
data = dict()
data['홍길동']='97'
data['이순신']='98'
print(data)
b={
'홍길동':97,
'이순신':98
}
print(b)
key_list=list(b.keys())
print(key_list)
a = 1
b = 2
print(a,b)
print(7, end=" ")
print(8, end=" ")
answer = 7
print("정답은"+str(answer)+"입니다.")
answer=7
print(f"정답은{asnwer}입니다")
score = 65
if score >= 90:
print("학점:A")
elif score >= 80:
print("학점:B")
elif score >= 70:
print("학점:C")
elif score >= 60:
print("학점 D")
else:
print("F!!")
score = 90
if score >= 90:
pass
else:
print("a < 90")
result = 0
for i in range(1,10):
if i%2 ==0:
continue
result += i
print(result)
list1 = [1,2,3,4,5]
list2 = [6,7,8,9,10]
result = map(lambda a,b:a+b, list1, list2)
print(list(result))
코딩테스트 유용한 표준 라이브러리
내장함수
순열과 조합
순열 :서로다른 n개에서 서로다른 r개를 선택하여 일렬로 나열하는것from itertools import permutations
data = ['A', 'B', 'C']
result = list(permutations(data,3))
print(result)
조합 : 서로다른 n개에서 순서에 상관없이 서로다른 r개를 선택하는 것
from itertools import combinations
data = ['A', 'B', 'C']
result = list(combinations(data,2))
print(result)
중복 순열 : product 함수 사용
from itertools import product
data = ['A', 'B', 'C']
result = list(product(data, repeat=2))
print(result)
중복 조합 : combinations_with_replacement 함수 사용
from itertools import combinations_with_replacement
data = ['A', 'B', 'C']
result = list(combinations_with_replacement(data, 2))
print(result)
Counter
from collections import Counter
counterArr = Counter(['red', 'blue', 'red', 'green', 'blue', 'blue'])
print(counterArr['blue'])
print(counterArr['green'])
print(counterArr['red'])
print(dict(counterArr))
Math 라이브러리
import math
def lcm(a,b):
return a * b // math.gcd(a,b)
a=21
b=14
print(math.gcd(21,14))
print(lcm(21,14))
Author And Source
이 문제에 관하여(파이썬 기본문법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dongmen5149/파이썬-기본문법저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)