Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Archives
Today
Total
관리 메뉴

배우고 느낀 것들

인프런 파이썬 입문 초반 3강 본문

파이썬/강의

인프런 파이썬 입문 초반 3강

낑깡H 2022. 8. 2. 14:03
sep='A' 프린트 안에 , 로 구분 된 요소들 사이에 A 넣어줌

 

 
EX) Print("010", "1234" , "5678", sep="-")
 
-> 010-1234-5678
end= "A"
Print 쓰면 줄바꿈 자동으로너무 많이 되는 걸 방지해줌. "" 으로 놔두면 한 줄로 쭉 이어줌
 

format 사용 : d정수 ,s문자열 ,f숫자
 

print( '%s %s' & ( 'one' , 'two')

print('{} {}' , format('one','two'))
 
결과는 동일 , 1번이 더 정석적
 
{} 안에 0,,1,2 ... 넣어서 순서 설정 간가능
 

%만 되는건가? 다른 기호로 하니까 안됨....
 
one two
print('@s %s' @('one') %('two'))
Traceback (most recent call last):
File "", line 1, in
print('@s %s' @('one') %('two'))
TypeError: unsupported operand type(s) for @: 'str' and 'str'
안 되는 거 맞는 거 같은데 다른 기호 되는거면 가능?
s + print
: s에 해당하는 숫자만큼 칸을 확보. s는 d,f와 달리 생략 가능. (기본값이 s?)
. 붙이면 그보다 긴 건 절삭
print ('%10s' % ('nice'))
nice
print('{:>10}' ,format('nice'))
{:>10} nice
print('{:>10)')
{:>10)
KeyboardInterrupt
print('{:>10}' ,format('nice'))
{:>10} nice
print('{:>10}'.format('nice'))
nice
print('{:<10}'.format('nice'))
nice
 
쉼표, 마침표 구분. 괄호 순서 틀리면 안댐!!!
 
print('{:$>10}'.format('nice'))
$$$$$$nice
print('{:^>10}'.format('nice'))
^^^^^^nice
print('{:^10}'.format('nice'))
nice
 
 

d: 정수
f : 정수부와 소수부 구분

 

 
여행 와서 괜히 노트북 들고왔나 싶었는데, 게시글 하나라도 남기니까 좀 뿌듯하닿
따라는 하는데, 이게 왜 중요한지 모르겠음
Comments