파이썬 정리

intp·2022년 6월 7일
0

Python

목록 보기
1/1
  1. 클래스 정의
class FirstClass():
	count = 0
    
	#__init__: 함수 정의할 때 A, B의 값 함께 저장(생성자)
	def __init__(self, A, B):
    	self.A = A
        self.B = B
        count += 1
        
    #정적 메소드    
    @staticmethod
    def countInstance():
    	print(FirstClass.count)

2-1. 문자열 분리

str = "가위, 바위, 보"
str.split(',')				=>	['가위', '바위', '보']
str = "가위 \n 바위 \n 보"
str.split()					=>	['가위', '바위', '보']

	#maxsplit split()의 개수 조절
str = "가위.바위.보"
str.split('.', maxsplit=1)	=>	['가위', '바위.보']

2-2 문자열 삭제

str = "aaaPYTHONbbb"
str.strip('ab')				=> 'PYTHON'
str = "aaareactaaa"
str.strip('a')				=> 'react'
	#한 쪽만 지우기 lstrip(), rstrip()
profile
공부합시다

0개의 댓글