728x90
반응형

1152번 문제

https://knowallworld.tistory.com/112

 

★코테에서 꼭 쓰이는★ 헷갈리는 문자열 정리

import sys #입력 216 N = int(sys.stdin.readline()) print(N) #출력 : 216 print(list(map(int,str(N)))) #출력 : [2,1,6] #입력 216 M = list(map(int ,sys.stdin.readline().rstrip())) print(M) #출력 : [2,1,6] O = list(map(str, sys.stdin.readline().rstri

knowallworld.tistory.com

VERSION 3.0

import sys

s = list(sys.stdin.readline().rstrip().split())

print(len(s))

VERSION 2.0

import sys

A = list(map(str, sys.stdin.readline().lstrip().rstrip().split()))
#split(' ')는 공백하나당 단어로 인식한다!
#따라서 split()는 공백길이와 상관없이 공백이 생기면 넘어간다.
print(len(A))

split('  ') 와 split() 함수의 차이 기억하기!!

VERSION 1.0

import sys

N = list(map(str,sys.stdin.readline().rstrip().split()))
M = []
for i in N:
    M.append(i.lower())
print(len(M))

★★★Key Point★★★

3번째줄:list(map(str,sys.stdin.readline().rstrip().split())) ==> 단어의 공백 기준으로 나누어 객체에 저장

list(map(str,sys.stdin.readline().rstrip())) ==> 단어 하나하나씩(공백 포함)하여 객체에 저장

 

 

 

728x90
반응형

+ Recent posts