본문 바로가기

👩🏻‍💻 DataScientist for Python/DataCamp

Introduction to Python 4 - Method

- Python에 여러가지 method를 소개한다.

string, float, list 등 어떤 type이던지 모두 object 인데 method는 object에 적용된다.

 

- list method

- list에 .index() 를 해주면 해당 내용에 있는 index번호를 출력한다.

- .count()를 해주면 그 리스트에 해당 내용이 몇개있는지 출력한다.

- str method

- .capitalize() 를 해주면 string에 첫번째 문자를 대문자로 출력한다.

- .replace("a", "b") 일때 a 를 b로 변경한다.

- .append() 를 해주면 기존에 있는 리스트에 내용을 추가할 수 있다.

- 연습

- .reverse() method는 사용할때 () 안에 어떤 값도 넣지 않는다. 저렇게 되면 areas 의 리스트에 있는 값들을 뒤에서 부터 출력한다.

- 연습

- package import

 

 

슬라이드 출처 : Datacamp - Datascientist with python

https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functions-and-packages?ex=1