print(abs(-5))
print(pow(4,2))
print(max(5,12))
print(round(3.14))
# math 연산자 관련 모듈
from math import *
print(floor(-4.99))
print(trunc(-4.99))
출력결과
5
16
12
3.1
-5
-4
코딩테스트에 잘 쓰이는 랜덤함수이다.
from random import *
print(random()) # 0.0 ~ 1.0 미만의 임의의 값 생성
print(random()*10) # 0.0 ~ 10.0 미만의 임의의 값 생성
print(int(random()*10)) # 0 ~ 10 미만의 임의의 값 생성
print(int(random()*10)+1) # 1 ~ 10 이하의 임의의 값 생성
print(int(random()*45)+1) # 1 ~ 45 이하의 임의의 값 생성(로또)
print(randint(1,46)) # 1 ~ 45 이하의 임의의 값 생성(로또)
출력결과
0.3424331718946467
6.869113110524587
7
10
26
4
python = "Python is Amazing"
print(python.lower())#소문자로
print(python.upper())#대문자로
print(python[0].isupper())#n번째 자리 대문자로
print(len(python))#문자열 길이
print(python.replace("Python","Java"))#n1찾아서n2로 대체
index = python.index("n")#첫번째 n 자리 찾기
print(index)
index = python.index("n",index + 1)#두번째 n 자리 찾기
print(index)
print(python.find("Java")) #없으면 -1 반환
#print(python.index("Java")) #없으면 바로 에러발생하여 다음 처리에 문제가 생길 수 있다.
print(python.count("n"))
출력결과
python is amazing
PYTHON IS AMAZING
True
17
Java is Amazing
5
15
-1
2