python print

sihwan_e·2020년 9월 3일
0

Python Dic

목록 보기
13/13
# print의 이해

print('Hello sir')
print("Hello sir")
print("""Hello sir""")
print('''Hello sir''')


# Separator 옵션 사용

print('T', 'E', "S", "T")
print('T', 'E', "S", "T")

print('T', 'E', "S", "T", sep='')
print('2019', '02', '19', sep='-')
# ''안의 것으로 연결해준다는 느낌임
print('niceman', 'google.com', sep='@')

# end옵션 사용
print('welcome To', end='')
print(' the black paradise', end='')
# 끝을 공백으로 처리하겠다 라는 의미 즉 그다음문장과 연결시키겠다는 것임.
print(' piano notes')


print('welcome To', end=' ')
print('the black paradise', end=' ')

print('piano notes')
print('fin')

# format 사용
print('{} + {}' .format('a', 'b'))
# a가 정의 된것이 아니라면 오류가 남, 따옴표 필요함.
print('{} and {}' .format("you", "me"))
print("{0}+{1}+{2}" .format(1, 2, 3))
print("{0}+{1}+{2}" .format('1', '2', '3'))
print("{a} are {b}" .format(a="you", b='me'))  # 이게 실수를  가장 줄이는 방법

# %s : 문자  %d : 정수  %f : 실수
print("%s's favorite number is %d" % ('jack', 7))
# 5자리 정수, 정수부분4자리 소수2자리의 실수
print("test1 : %5d, price: %4.2f" % (776, 6534.1234))
print("test1 : %5d, price: %4.2f" % (7444476, 6534.1234))
print("test1 : %5d, price: %4.2f" % (776333, 6534.1234))
# 5자리만 제한되는거 아님? 왜걍 되냐
print("test1: {0: 5d}, price: {1: 4.2f}" .format(776, 65435.1234))
# 중괄호로 해놨으면 %안써도됌

print("test1: {a: 5d}, price: {b: 4.2f}".format(a=776, b=1234.12414))

# escape code
# \다음 거는 그대로 표기해준다
print("'you'")
print('\'you\\')
print('"you"')
print("""'you'""")
print('\\you\\')

print('\\you\\\n')
print("test")

a = 5.
b = 4
print(type(a), type(b))


# data type

a = 5.
b = 4
c = 10
print(type(a), type(b))
result = a + b
print(result)

# 형변환
print(int(result))
print(float(c))
print(complex(3))
print(int(True))
print(int(False))
print(int("3"))
print(complex(False))

print(abs(-7))  # 절댓값
n, m = divmod(100, 8)   #몫과 나머지
print(n, m)
>>>12 4


print(math.ceil(5.1))  # 5.1보다 큰 가장 작은 정수 6
print(math.floor(3.874))  # 3.874 보다 작은 가장 큰 정수 3


profile
Sometimes you gotta run before you can walk.

0개의 댓글