반응형
Output Variables
The Python print statement is often used to output variables.
To combine both text and a variable, Python uses the + character:
adjective = "awesome"
print("Python is " + adjective)
# ' Paython is awesome ' 출력
adjective = "amazing"
noun = "Java"
print("Python is " + adjective + "?")
print("What about " + noun + "?")
You can also use the + character to add a variable to another variable:
+ 를 통해서 다른 변수들과의 값을 합칠 수가 있다.
noun = "Python "
verb = "is "
adjective ="awesome "
sentence = noun + verb + adjective
print(sentence)
For numbers, the + character works as a mathematical operator:
숫자들간의 계산도 가능하다.
num1 = 1000
num2 = 900
num3 = 95
result = num1+num2+num3
print(result) #출력 1995
If you try to combine a string and a number, Python will give you an error:
자바와 다르게 숫자와 문자타입의 변수를 더한다고 해서 문자로 변경되지 않고 오류가 뜬다.
num = 10
word = "자수"
print(num + word)
반응형
'python > w3schools' 카테고리의 다른 글
파이썬 w3schools 정리 (0) | 2021.10.05 |
---|---|
[w3schools] Global Variables - Python Variables (0) | 2021.05.31 |
[w3schools] Assign Multiple Values - Python Variables (0) | 2021.05.25 |
[w3schools] Variable Names - Python Variables (0) | 2021.05.24 |
[w3schools] Python Variables - Python Variables (0) | 2021.05.20 |