코드업 기초 100제 출력,입출력 파트
print("Hello")
print("Hello World")
print('''Hello
World''')
\n 개행 문자를 써도 되지만 코드잇에서 '''를 이용할 수도 있다고 배웠던게 기억난다.
print("'Hello'")
print('"Hello World"')
print("\"!@#$%^&*()\'")
Python 에서 \, ", ' 순서대로 백슬래시, 큰따옴표, 작은따옴표를 print 출력하기 위해서는 해당 문자 앞에 \ (백슬래시)를 붙여서 적어줘야한다.
print("\"C:\\Download\\'hello\'.py\"")
print('"C:\Download\\'hello\'.py\"') 풀이도 있음. 바깥부분의 '를 "와 구분해주고 내부를 \백슬래시를 이용하여 출력해주면 됨.
print("print(\"Hello\\nWorld\")")
**이 문제도 마찬가지로 복잡하게 생각할것 없이 출력의 "와 일반의 "를 구분해주고 백슬래시도 \ 를 붙이면 된다.
ch = input()
print(ch)
n = input()
n = int(n)
print(n)
n = input()
n = float(n)
print(n)
a = int(input())
b = int(input())
print(a)
print(b)
a = input()
b = input()
print(b)
print(a)
a= float(input())
for i in range(3):
print(a)
1 2
1
2
a, b = input().split()
a=int(a)
b=int(b)
print(a)
print(b)
input().split() 를 사용하면, 공백 을 기준으로 입력된 값들을 나누어(split) 자른다.
int(input()).split 해봤는데 안됐다. 정수로 변환해주는것은 따로 구분해주자 .
a b
b a
c1,c2 = input().split()
print(c2,c1)
, 를 하면 자동으로 출력할 때 띄어줌
computer science
computer science computer science computer science
s = input()
print(s,s,s)
파이썬에서 정수는 정수끼리 , 문자열은 문자열끼리 연산 가능하다.
그래서 정수의 의미를 챙기고 싶을 때 정수로 변환해줘야할 때가 있는 것.
3:16
3:16
a,b = input(split(':'))
print(a,b,sep = ':')
(?,?,sep = 'ㅁ') : ㅁ기호 사이에 두고 a와 b를 출력해주룜
sep 는 출력할때 쓰는 변수들간의 분류기호.
split는 입력할때 쓰는 변수들간의 분류기호. 순서대로 저장한다 로 일단 이해해보자
2020.3.4
4-3-2020
y, m, d = input().split('.')
print(d,m,y,sep = '-')
3개 이상 sep 할때도 마찬가지.
000907-1121112
0009071121112 (붙여쓰시옹)
front, back = input().split('-')
print(front+''+back)
붙여쓴 ''는 리터럴리 아무것도 아닌것. 공백도 아니고 의미를 갖지도 않고!
s = input()
for i in range(5) :
print(s[i])
200304
20 03 04
date = input()
print(date[0:2],date[2:4],date[4:6])
이렇게 해도 공백으로 나왔지만,
17:23:57
23 시분초 중 분만 출력
h,m,s = input().split(':')
print(m)
붙여서 출력하기
w1, w2 = input().split(' ')
s = w1 + w2
print(s)