데이터 취업 스쿨 스터디 노트 -(4) datetime, isdigit

테리·2024년 6월 6일

날짜 출력 모듈

: datetime

import datetime
today = datetime.datetime.today()
print(today)

문자의 길이를 반환

: len()

특정문자열의 위치를 찾음

: find()
첫번째 위치는 '0'이다.

article = ('오늘은 아임웹 모바일 게시판 위젯창은 글쓰기 버튼이 2개인 것을 확인하실 수 있으실 텐데요?'
           '리스트가 길어지는 것을 생각하여 버튼이 2개로 구성되어 있습니다.')
ind = article.find('아임웹')
print('아임웹 문자열 위치: {}'.format(ind))

cf) input() 함수 사용시 사용자한테 입력받은 것은 전부 문자이다. 그래서 int 같은것으로 변환을 해줘야함.
ex) int(input())

isdigit()

: 숫자인지 확인. 숫자이면 True, 아니면 False

weight = input('체중 입력(g): ')
height = input('신장 입력(cm): ')

if weight.isdigit():      #만약 True면
    weight = int(weight)/1000

if height.isdigit():
    height = int(height) / 100

0개의 댓글