python) Concatenating Text Strings

3204 ワード

" Concatenating Text Strings "


文字列プラス記号
文字列を接続する必要がある場合
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.