1. +를 이용한 방식
print("hello, " + "world!") # hello, world!
2. , 를 이용한 방식
print("hello, ", "world!") # hello, world!
3. %d, %c, %s ... 를 이용한 방식
print("hello %s" % "world") # hello world
print("hello %s %s" % ("python", "world")) # hello python world
4. {}, format을 이용한 방식
print("hello {}".format("world")) # hello world
print("hello {}{}".format("python", "world")) # hello python world
print("hello {0}{1}".format("python", "world")) # hello python world
print("hello {1}{0}".format("python", "world")) # hello world python
5. {}, format을 이용한 방식, 변수 선언
print("hello {name}, {where}".format(name = "J3SUNG", where = "Python")) # hello J3SUNG, Python
6. 3.6v 이후에 사용 가능한 f를 문자열 전에 입력한 후 사용
name = "J3SUNG"
where = "Python"
print(f"hello {name}, {where}") # hello J3SUNG, Python
'Python' 카테고리의 다른 글
[파이썬] 리스트 (0) | 2020.09.10 |
---|---|
[파이썬] 탈출문자 (0) | 2020.09.10 |
[파이썬] 문자열 처리 함수 (0) | 2020.09.10 |
[파이썬] 슬라이싱 (0) | 2020.09.10 |
[파이썬] 문자열 (0) | 2020.09.10 |