print('Hello Word')
>> Hello World
print('I', 'love', 'Python', sep = '-') # - 로 문자열 구분
>> I-love-Python
print("James is my friend.\nHe is Korean.") # 개행문자 \n
>> James is a my friend.
He is Korean.
oper = '반지름' # 문자 데이터 할당
r = 3 # 정수 데이터 할당
PI = 3.14159265358979 # 실수 데이터 할당
print("%s: %d, 원주율: %f" % (oper, r, PI))
>> 반지름: 3, 원주율: 3.141593
animal_0 = "cat"
animal_1 = "dog"
animal_2 = "fox"
print("Animal: {}, {}, {}".format(animal_0, animal_1, animal_2))
print("Animal: {1},{2},{0}".format(animal_0, animal_1, animal_2)) # 위치 지정
>> Animal: cat, dog, fox
Animal: dog, fox, cat
a = 0.1234567890123456789
print("{0:.2f}, {0:.5f}".format(a))
>> 0.12, 0.123456
엔터로 입력할 수 있다.
a = input("정사각형 한 변의 길이는?: ")
area = int(a) ** 2
print("정사각형의 넓이: {}".format(area))
>> 정사각형 한 변의 길이는?: 4
정사각형의 넓이: 16