Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 아스키코드
- DOM
- 노마드코더
- 장고
- popupmenubutton
- 포인터
- 부스트코스
- JavaScript
- 성수동카페
- 남양주맛집
- richtext
- FLUTTER
- 코딩독학
- 자바
- 알고리즘
- 속초여행
- python3
- BeautifulSoup
- 정렬알고리즘
- 상속
- 강원도속초맛집
- 건대입구맛집
- Django
- removetooltip
- pipenv
- c언어문자열
- 컴퓨터과학
- Python
- 가상환경
- 추상클래스
Archives
- Today
- Total
YUYANE
Python/ format() Method 본문
The String format() Method
{}안에 들어가는 문자는 format 함수에 들어간 개체로 대체됨.
>>> print('We are the {} who say "{}!"'.format('knights', 'Ni'))
We are the knights who say "Ni!"
{} 안에 들어가는 숫자는 format 함수에 들어있는 개체의 순서를 나타내기도 한다.
print('{0} and {1}'.format('spam', 'eggs'))
spam and eggs
>>> print('{1} and {0}'.format('spam', 'eggs'))
eggs and spam
{} 안에 매개 변수가 사용되면, format 함수에서 해당 매개 변수의 값을 참고한다.
>>> print('This {food} is {adjective}.'.format(
... food='spam', adjective='absolutely horrible'))
This spam is absolutely horrible.
positional arguments랑 keyword arguments랑 섞어서 사용할 수도 있다.
>>> print('The story of {0}, {1}, and {other}.'.format('Bill', 'Manfred',
other='Georg'))
The story of Bill, Manfred, and Georg.
[]을 사용해서 해당 dict의 key 값에 접근할 수도 있다.
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
>>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; '
... 'Dcab: {0[Dcab]:d}'.format(table))
Jack: 4098; Sjoerd: 4127; Dcab: 8637678
참고
docs.python.org/3/tutorial/inputoutput.html
7. Input and Output — Python 3.9.1 documentation
7. Input and Output There are several ways to present the output of a program; data can be printed in a human-readable form, or written to a file for future use. This chapter will discuss some of the possibilities. 7.1. Fancier Output Formatting So far we
docs.python.org
'Programming Languages > PYTHON' 카테고리의 다른 글
Python / Regular Expression(Regex) (0) | 2021.01.13 |
---|---|
Python/ 문자열에서 특정 인덱스 값 다음의 문자를 찾을 때 유의 (0) | 2021.01.06 |
Python/ 환경변수(Path) (0) | 2020.12.24 |
Python/ Beautiful Soup (0) | 2020.12.18 |
Python/ Requests (0) | 2020.12.17 |
Comments