python/w3schools

[w3schools] Output Variables - Python Variables

유호야 2021. 5. 25. 22:31
반응형

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)
반응형