728x90 반응형 Element2 [Python] extend()로 List 자료형에 List 요소 추가하기 LIST.extend()extend()는 리스트뿐 아니라 튜플, 집합(set) 등 다양한 자료형의 요소를개별적으로 풀어서 리스트에 순서대로 덧붙이는 기능을 제공합니다.extend() 특징간결한 코드 작성여러 요소를 추가할 때 for 루프나 append()를 반복적으로 호출할 필요가 없습니다.다양한 자료형에 적용 가능리스트뿐 아니라 튜플, 집합, 문자열 등 다양한 자료형의 요소를 추가할 수 있습니다.thislist = ["apple", "banana", "cherry"]tropical = ["mango", "pineapple", "papaya"]# extend()를 사용하여 tropical의 요소를 thislist에 추가thislist.extend(tropical)print(thislist)# ['appl.. 2024. 11. 18. [Python] BeautifulSoup select() CSS 선택자 사용법 BeautifulSoup(html, 'html.parser').select()select() 메서드는 HTML 문서에서 CSS 선택자 규칙에 맞는 모든 태그를 리스트 형태로 반환 예제 HTML 코드# HTML 문서를 파싱하여 soup 객체 생성from bs4 import BeautifulSouphtml = """ The Dormouse's story Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; """soup = BeautifulSoup(html, 'html.parser')활용태그 이름으로 찾기soup.select("title")# 결과: [The Dormou.. 2024. 11. 17. 이전 1 다음 728x90 반응형