Python은 단순하고 강력한 문법 덕분에, 기본 메서드만 제대로 사용해도 코드 품질과 효율성이 크게 향상됩니다.
아래 핵심 메서드 + 실전 예제로 Python 활용 능력을 한 단계 올려보세요.
🔤 String Methods
문자열 처리는 데이터 전처리, NLP, 웹 개발 등 거의 모든 분야에서 필수입니다.
| Method | Description |
|---|---|
upper() | 모든 문자를 대문자로 변환 |
lower() | 모든 문자를 소문자로 변환 |
strip() | 앞뒤 공백 제거 |
split() | 문자열을 리스트로 변환 |
join() | 리스트를 문자열로 결합 |
replace() | 문자열 치환 |
💡 Example
text = " Hello Python World "
print(text.upper()) # " HELLO PYTHON WORLD "
print(text.strip()) # "Hello Python World"
print(text.split()) # ['Hello', 'Python', 'World']
words = ["Python", "is", "fun"]
print(" ".join(words)) # "Python is fun"
print(text.replace("Python", "AI")) # " Hello AI World "
📋 List Methods
효율적인 데이터 구조 활용은 개발자의 기본 스킬입니다.
| Method | Action |
|---|---|
append() | 요소 추가 |
insert() | 지정 위치에 삽입 |
remove() | 요소 제거 |
sort() | 정렬 |
pop() | 요소 제거 + 반환 |
💡 Example
nums = [3, 1, 4]
nums.append(2)
print(nums) # [3, 1, 4, 2]
nums.sort()
print(nums) # [1, 2, 3, 4]
nums.pop()
print(nums) # [1, 2, 3]
🔧 Set Methods
중복 제거와 집합 연산에 최적화되어 있습니다.
| Method | Use |
|---|---|
add() | 요소 추가 |
discard() | 요소 제거 (오류 없음) |
union() | 합집합 반환 |
intersection() | 교집합 반환 |
difference() | 차집합 반환 |
💡 Example
a = {1, 2, 3}
b = {3, 4, 5}
print(a.union(b)) # {1, 2, 3, 4, 5}
print(a.intersection(b)) # {3}
print(a.difference(b)) # {1, 2}
a.add(6)
print(a) # {1, 2, 3, 6}
📁 File Handling Methods
파일 입출력은 항상 with문과 함께 사용하세요 — 자동으로 close 처리됩니다.
| Method | Purpose |
|---|---|
read() | 파일 전체 읽기 |
readline() | 한 줄 읽기 |
write() | 파일에 쓰기 |
seek() | 파일 포인터 이동 |
tell() | 현재 위치 확인 |
💡 Example
with open("demo.txt", "w") as f:
f.write("Python File Handling Example")
with open("demo.txt", "r") as f:
print(f.read()) # "Python File Handling Example"
🧠 Why This Matters
✔️ 더 간결한 코드
✔️ 더 빠른 개발 속도
✔️ 유지보수성과 확장성 향상
Python 기본기를 잘 다루는 개발자는 더 똑똑하게 일합니다, 더 많이가 아니라. 💡
🛠️ Our Services
👉 Production-grade LLM + NLP 시스템 구축
👉 Scalable Cloud AI Engineering & Integration