본문 바로가기
  • Slow and Steady wins the race

abt Python/기초8

python 문자열, 텍스트 문자열과 텍스트 문자열 분리 : split() lunch_menu_str = "돈까스,된장찌개,두루치기,순두부" lunch_menu_str .split(",") # split 메소드 사용 (,를 기준으로 분리) # ['돈까스', '된장찌개', '두루치기', '순두부'] "돈까스,된장찌개,두루치기,순두부".split(",") # , 를 기준으로 split (텍스트 바로 써도 됨) # ['돈까스', '된장찌개', '두루치기', '순두부'] # 아무것도 지정하지 않으면 공백과 엔터를 기준으로 split " 돈까스 \n 된장찌개 \n 두루치기 \n순두부".split() # ['돈까스', '된장찌개', '두루치기', '순두부'] # 단어의 개수 지정 가능 "돈까스 된짱찌개 두루치기 순두부".split(maxspl.. 2023. 8. 12.
python 객체와 클래스 객체와 클래스 객체란 속성(상태, 특징)과 행위(행동, 동작, 기능)로 구성 클래스는 객체를 만들기 위해 활용되며, 객체의 공통된 속성과 행위를 변수와 함수로 정의한 것 클래스 선언 class Car(): def moves(self, speed): print("자동차: 시속{}킬로 미터로 전진".format(speed)) def turn(self, direction): print("자동차: {}로 회전".format(direction)) def stop(self): print("자동차({0},{1}): 정지".format(self.wheel_size, self.color)) my_car=Car() my_car.wheel_size=18 my_car.color="yellow" my_car.moves(40) .. 2023. 8. 10.
python 기본 함수 함수 함수의 종류별 처리 방법 1) 인자도 반환 값도 없는 함수 # 인자나 반환값이 없는 함수 def func(): print("This is my first function.") print("It is good") func() # This is my first function. # It is good 2) 인자는 있으나 반환 값은 없는 함수 # 인자는 있으나 반환값이 없는 함수 def friend(Name): print("{}는 나의 친한 친구입니다.".format(Name)) friend("정국") friend("Rachel") # 정국는 나의 친한 친구입니다. # Rachel는 나의 친한 친구입니다. def student_info(name, s_number, p_number): print("----.. 2023. 8. 10.
python 입력과 출력 입력과 출력 print() 함수를 이용하여 문자열과 숫자열을 출력할 수 있다. print("Hello Python") # Hello Python 문자열을 출력할 경우 "", ''를 이용하여 출력할 수 있다. print("Best", "python", "course") # Best python course 문자열 내에 sep = 구분자를 추가하여 문자열 사이를 구분할 수 있다. print("Best", "python", "course", sep="*") # Best*python*course + 연산자를 이용하여 문자열을 연결할 수 있다. print("Best"+"python"+"course") # Bestpythoncourse \n 을 이용하여 출력 시 줄을 바꿀 수 있다. print("Jun is my .. 2023. 8. 10.