Skip to content

Instantly share code, notes, and snippets.

@nattybear
Created June 3, 2017 18:06
Show Gist options
  • Select an option

  • Save nattybear/b9dbfbb54b159a6e1b432d559a9bd1a6 to your computer and use it in GitHub Desktop.

Select an option

Save nattybear/b9dbfbb54b159a6e1b432d559a9bd1a6 to your computer and use it in GitHub Desktop.
# 글자로만 구성된 문자열
str1 = "hello"
# 숫자가 포함된 문자열
str2 = "hello123"
# isdigit()는 문자열 객체의 메소드이다.
# 문자열에 숫자가 포함되어 있는지 아닌지를
# 검사해서 숫자가 있으면 참을 리턴하고
# 숫자가 없으면 거짓을 리턴한다.
a = str1.isdigit()
b = str2.isdigit()
print(a) # False
print(b) # True
@nattybear

Copy link
Copy Markdown
Author

메소드에 is라는 단어가 들어가면 참거짓

  • 영어에서 Is he good?과 같이 is가 앞에 오면 물어보는 문장이 된다.
  • 파이썬에서 메소드 이름에 is가 들어가면 참거짓을 리턴하는 함수일 가능성이 크다.
  • 위 예제에서 hello 문자열에는 숫자가 하나도 없으므로 isdigit의 결과는 거짓이 된다.
  • 반대로 hello123 문자열에는 숫자가 포함되어 있으므로 참을 리턴한다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment