코딩테스트준비/Python

[Python] 함수 및 이것저것 아카이브

zyari 2023. 1. 28. 06:25
반응형

1. 삼항연산자

len1과 len2중 더 작은 수를 num 변수에 저장하기

num = len1 if len1<len2 else len2

 

2. 특정 문자열을 기준으로 슬라이스

string = [1.2.3.4.5]
result = string.split(".")

#반환: [1, 2, 3, 4, 5]

 

3. string의 각각 문자열들이 숫자 범위 안에 없을 경우 특정 코드 실행 (string -> ascii 변환해주는 함수: ord())

if ord(i) < 48 or ord(i) > 57:
	print("i is not a numerical value")

 

반응형

'코딩테스트준비 > Python' 카테고리의 다른 글

[Python] Linked-List 구현하기  (0) 2023.01.28