View

TIL 13 | PYTHON_String Concatenation

Melody:) 2021. 8. 5. 17:44

숫자만 더한다고!?? 파이썬에서는 문자도 더할 수 있다!!


String Concatenation

 

print("Hello, " + "World")

 

input() 을 통해 유저로부터 받은 이름을 저장한 변수를 화면에 출력하고 싶을 때, 사용 가능!

name = input()
 
print("Hello, " + name)

👉 " Hello, Melody"

👉 " Hello, 철수"


문자열이 너무 길고 복잡하다면!???


literal string interpolation 

+ 를 사용하지 않고도 문자열을 더할 수 있다.

 

👉 사용방법

date            = 1980
python_inventor = "Guido van Rossum"
location        = "Centrum Wiskunde & Informatica"
country         = "Netherlands"
 
print(f"""Python was conceived in the late {date}s 
by {python_inventor} at {location} (CWI) in the {country} as a successor 
to the ABC language (itself inspired by SETL), capable of exception handling 
and interfacing with the Amoeba operating system. 
Its implementation began in December 1989.""")
  1. 먼저 따옴표 앞에 f  붙이기
  2. 치환 하고 싶은 변수 를 {}를 사용해서 표시하기
    (혹은 변수가 아니어도 됩니다. 예를 들어 함수 호출이 될 수도 있습니다) 

'PYTHON' 카테고리의 다른 글

TIL 18 | PYTHON_Tubles  (0) 2021.08.09
TIL 14 | PYTHON_IF  (0) 2021.08.05
TIL 12 | PYTHON_Math Expressions  (0) 2021.08.05
TIL 11 | PYTHON_Variables  (0) 2021.08.05
TIL 10 | PYTHON_Print_DataType  (0) 2021.08.05
Share Link
reply
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31