[Python] print( ) & 문자열 (str) 1번째 (2557번, 10718번)
print( )
1) 숫자 출력
ex) print(45)
>>>45
1-1) 연산한 결과 출력
ex) print(4+5)
>>>9
2) 문자(열) 출력
ex) print("Python Coding")
>>>Python Coding
print("1+5")
>>>1+5
3) 변수 출력
ex) words = "Hello"
print(words)
>>>Hello
4) 변수 + 문자 출력
4-1)format
ex) words = "Hello"
words_2 ="Python3"
print("{0} {1} world {2}".format(words, words_2, "wow"))
>>>Hello Python3 word wow
: print("{} {}".format(변수1, 변수2))
>>>변수1 변수2
: print("{1} {0}".format(변수1, 변수2))
>>>변수2 변수1
ex) words ="Hello {words_2}"
print(words.format(words_2 = "Python3"))
>>>Hello Python3
ex) a =5
b= 3
print("{}와 {}를 더한 값은 {}".format(a,b,a+b))
>>>5와 3를 더한 값은 8
4-2)f-string
ex) words = "Hello"
words_2 ="Python3"
print(f"{words} {words_2} world")
>>>Hello Python3 world
ex) words =f"Hello {words_2}"
words_2 = "Python"
print(f"{words} world!!")
>>>Hello Python world!!
ex) a =5
b= 3
print(f"{a}와 {b}를 더한 값은 {a+b}")
>>>5와 3를 더한 값은 8
https://multitasker-sh.tistory.com/2
[Python] print( ) & 문자열 (str) 2번째 (10718번, 10172번)
print 1)print("Hello word")은 print("Hello word", end='\n')와 같다 \n => 개행(enter) print("Hello world"여기) 여기에 특별한 값을 넣지 않으면 print문이 수행되고 끝에 \n(enter)가 들어간다. ex)print("Hello") print() print("wo
multitasker-sh.tistory.com