데이터 꿈나무

[Python] 문자열에서 특정 문자 개수 세기(count) 본문

Language/Python

[Python] 문자열에서 특정 문자 개수 세기(count)

ye_ju 2023. 2. 7. 23:34

예제로 간단하게 살펴볼게요


1~50의 숫자가 들어간 list에서 1의 개수 세기

answer = 0

for i in range(1, 51):
	answer += str(i).count('1')
    
print(answer)

 

Comments