헷갈리는 것 위주로 정리하였다.
format 형태
x, y = 3, "hi"
print("x is {0} and y is {1}" .format(x, y))
print("x is {} and y is {}" .format(x, y))
print("x is {new_x} and y is {new_y}" .format(new_x=x, new_y=y))
f string 형태
first_name = "John"
print(f"Hello, {first_name}!")
소수점
"{ : .2f }.".format(실수 혹은 변수) : 소수점 3번째 자리에서 반올림을 해서 2자리 까지 출력
f'{변수:.2f}': 소수점 3번째 자리에서 반올림을 해서 2자리 까지 출력
※소수점 처리
round(실수 혹은 변수, 2): 소수점 3번째 자리에서 반올림을 해서 2자리 까지 출력
올림: math.ceil()
내림: math.floor()
'Computer Science > +α' 카테고리의 다른 글
도커(Docker)란? (0) | 2024.01.16 |
---|---|
[SWEA] 사용 가능 라이브러리 (Python) (0) | 2023.11.14 |
프레임워크 라이브러리 차이!! (0) | 2023.11.07 |
JPEG 압축원리 / JPEG는 lossless한 포맷인가? (1) | 2023.02.02 |
[Git] git 기초, github (0) | 2022.01.27 |