반응형

분류 전체보기 416

문자열 포맷별 출력

문자열포맷 구분% 기호 방식{} 기호 방식f-strings 방식출력 결과문자열'%s' % 'string''{}'.format('string')s = 'STRING'; f'{s.lower()}''string'문자'%c' % 0x41'{:c}'.format(0x41)f'{0x41:c}''A'십진수'%d' % 0xFFFF'{:d}'.format(0xFFFF)f'{0xFF00+0x00FF:d}''65535'부동소수'%.2f' % 3.141592'{:.2f}'.format(3.141592)f'{3.141592:.2f}''3.14'16진수(소문자)'%x' % 65535'{:x}'.format(65535)f'{65535:x}''ffff'16진수(대문자)'%X' % 65535'{:X}'.format(65535)f'{6..

개발/Python 2021.04.16

파이썬 튜플(tuple)

튜플은 소괄호('(', ')')로 표시하며 원소를 변경할 수 없다. >>> myTuple = ('a', 'b', 'c', [10, 20, 30], abs, max) >>> myTuple ('a', 'b', 'c', [10, 20, 30], , ) 5번째 원소인 내장함수 abs()에 -100을 파라미터로 전달 >>> myTuple[4](-100) 100 6번째 원소인 내장함수 max()에 리스트([10, 20, 30])를 파라미터로 전달 >>> myTuple[5](myTule[3]) 30 원소 변경 시 >>> myTuple[0] = 'A' TypeError: 'tuple' object does not support item assignment 참조 : (도서) 파이썬 증권 데이터 분석 / 김황후 저

개발/Python 2021.04.16

파이썬 join() 함수

리스트를 인수로 받아서 문자열을 하나로 만든다.>>> myList = ['one', 'two', 'three']>>> myList['one', 'two', 'three'] - 결합하고자 하는 문자를 이용하여 하나의 문자열을 만든다.스페이스(' ')를 이용하여 join>>> ' '.join(myList)'one two three' 컴마(',')를 이용하여 join>>> ', '.join(myList)'one,two,three' 컴마스페이스(', ')를 이용하여 join>>> ', '.join(myList)'one, two, three' 빈문자열('')을 이용하여 join>>> ''.join(myList)'onetwothree'

개발/Python 2021.04.16

파이썬 split() 함수

split() 함수는 문자열을 분리하여 리스트로 만들 때 사용인수가 없으면 빈 스페이스(' ')로 분리하고 인수가 있으면 인수로 분리한다. 인수 없이 분리>>> str = 'one two three'>>> myList = str.split() >>> type(myList) >>> myList['one', 'two', 'three'] 인수 없이 분리하는데 빈 스페이스(' ')가 없는 경우>>> str = 'one,two,three'>>> myList = str.split()>>> myList['one,two,three'] 인수(예, 컴마(','))로 분리>>> str = 'one,two,three'>>> myList = str.split(',')>>> myList['one', 'two', 'three']..

개발/Python 2021.04.16
반응형
LIST