문자열의 더하기
string 을 이어야 할 때
string + string 형태로 사용할 수 있다.
print("hello" + "world")
# 출력
실행결과> helloworld
literal string interpolation
- 문자 따옴표 앞에 f 를 붙인다.
- 치환하고 싶은 변수를 { } 을 사용해서 표시한다.
( 꼭 변수가 아니어도 된다, 함수 호출이 될 수도 있다.)
예)
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.""")
# 출력
실행결과>
Python was conceived in the late 1980s
by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands 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.