최대 1 분 소요

2배속으로 강의 들으면서 대충 기억날랑말랑한 녀석들 정리

string에서 index 찾기


test = "강고트"
test.find("강")

# a.jpg만 찾고싶을 때
path = "c:\\test\\goat\\ganggoat\\a.jpg"
path[path.rfind("\\") + 1:]
path.split("\\") # 다 쪼개져서 나옴
  • isdecimal : 10진수인지
  • isdigit : 아라비아숫자인지
  • isnumeric : 숫자인지

대충 리스트 다루기

a = [1, 2, 3, 4]
a.append(5)
a.insert(0, 0)
del a[1]

파일 읽고 쓰기

줄바꾸고 싶을 때 역슬레시 하나 넣어주면 된다…? 이건 몰랐네 ```python file1 = open(“sample.txt”, mode=”w”, encoding=”utf-8”) file1.write(“강고트의 파이썬 복습”) file1.close()

with open(“sample.txt”, mode=”r”, encoding=’utf-8’) as f1,
open(“sample2.txt”, mode=”w”, encoding=’utf-8’) as f2: f2.write(f1.read().replace(‘파이썬’, ‘python’)) ```

아직 별로 기억할만한 내용이 없다… 일단 입력된 문자열은 무조건 문자열형태로 입력된다.

댓글남기기