print("hello")
----------------
hello
,로 구분하면 공백 생성하여 출력+로 구분하면 공백 없이 이어서 출력print("hello", 1, 2.0+[a, b, 'text'])
----------------------------------------
hello 1 2.0[a, b, 'text']
sep = "구분 기호"를 작성하여 구분 단위 변경공백으로 단위를 구분print("hello", 1, 2.0, [a, b, 'text'], sep=", ")
hello, 1, 2.0, [a, b, 'text']
end = "문자열"을 이용하면 마지막 문장에 문자열 출력end = "" : 엔터(줄 바꿈) 삭제print("줄 바꿈 삭제.", end="")
print("느낌표 출력", end="!")
줄 바꿈 삭제.느낌표 출력!
r" "print("그대로\t출력")
print(r'그대로\t출력')
그대로 출력
그대로\t출력
strip(인자) : 인자를 str 왼쪽, 오른쪽에서 제거lstrip(인자)은 왼쪽에서, rstrip(인자)은 오른쪽에서 제거text = "123abc!@#"
print(text.strip('12#'))
print(text.lstrip('12#'))
print(text.rstrip('12#'))
3abc!@
3abc!@#
123abc!@
변수.split(“ ”) - “ ”를 기준으로 각각 분열“ ”.join(변수) - 변수 내용 각각 사이에 “” 추가"%alphabet" % (var) : var 값을 %alphabet 위치에 출력%s 문자열을 대입한 변수 출력%d 정수를 대입한 변수 출력%f 실수를 대입한 변수 출력"%s, %d, %f" % (대입할 변수1, 변수2, 변수3))str_s = "나머지"
int_d = 15
float_f = 3.0
print("%d 안녕 %s 파이썬 %f" % (int_d, str_s, float_f))
15 안녕 나머지 파이썬 3.0
"{}".format() : () 값을 {} 위치에 출력
'{인덱스0}, {인덱스1}'.format(값0, 값1)
animal_0 = "cat"
animal_1 = "dog"
animal_2 = "fox"
print("Animal: {0},{1},{2}".format(animal_0, animal_1, animal_2))
Animal: cat, dog, fox
{0: .nf}.format(값)n번째 자리 소수점까지 출력a = 0.1234567890123456789
print("{0:.2f}, {0:.5f}".format(a))
0.12, 0.12346
f"{출력하고자 하는 값}"a = 3
b = 2
print(f"a = {a}\nb = {b}")
a = 3
b = 2
input_value= input("text : ")
text : 사용자가 입력한 값(str)
문자열 strint()float()input("숫자 쓰기 : ")
int(input("정수만 쓰기 : "))
int(input("다른거 쓰면 오류남 : ))
float(input("실수만 쓰기 : "))
숫자 쓰기 : 3 # type : str
정수만 쓰기 : 3 # type : int
다른거 쓰면 오류남 : 2.0 # Error
실수만 쓰기 : 2.0 # type : float
| 구분 | 설명 |
|---|---|
| \n | 엔터 출력 |
| \t | Tab 공백 출력 |
| \b | 앞에 하나 삭제 (backspace) |
| \r | 앞에 내용 전체 삭제 |