내장 함수
print(abs(-500)) # 절대값
print(pow(2,20)) # 제곱
print(max(1,100)) # 최대값
print(min(1,100)) # 최소값
print(round(3.3)) # 반올림
math 함수
from math import *
print(floor(4.99)) # 내림 4
print(ceil(3.14)) # 올림 4
print(sqrt(16)) # 제곱근 4
random 함수
from random import *
print(random()) # 0.0 ~ 1.0 미만의 랜덤 값
print(random() * 10) # 0 ~ 1 미만의 랜덤 값
print(int(random() * 10))
print(randrange(1,46)) # 1 ~ 46 미만의 랜덤 값
문자열 처리 함수
python = 'hellow python'
print(python.upper()) # 대문자
print(python.lower()) # 소문자
print(python[0].isupper()) # 0번째 대문자 확인
print(python[1].islower()) # 1번째 소문자 확인
print(len(python)) # 자릿수
print(python.replace('python','c#'))
index = python.index('l')
print(index)
print(python.find('java'))
print(python.count('l'))
함수 생성
def pythonFunction():
print('hello python funtion')
def inputFunction(input, money):
print('입금 완료, 잔액은 {0}원 입니다.'.format(input + money))
return input + money
def outputFunction(output, money):
if output > money:
print('출금 불가, 잔액은 {0}원 입니다.' .format(money))
return money
else:
print('출금 완료, 잔액은 {0}원 입니다.'.format(money - output))
return money - output
money = 10000
action = inputFunction(5000 , money)
outputFunction(10000,action)
기본값 함수
def defaultFunction(name,age=30,language='python'):
print('이름 : {0} , 나이 : {1} , 언어 : {2}'.format(name,age,language))
defaultFunction('taco')
defaultFunction(language='c#', age=33, name='taco')