Python/etc.
-
Math modulePython/etc. 2020. 7. 28. 14:36
| import vs from~ import 사용법 : import greet from greet import hello, niceMeet 함수 : greet.hello() hello() greet.niceMeet() niceMeet() | Math Module 2행 : math.floor(3.47) -> 3 : 내림 3행 : math.ceil(5.1) -> 6 : 올림 4,5행 : math.round(A) : 반올림 값을 반환 7행 : math.factorial(5) -> 120 : 팩토리알 값 반환 math.fabs(-3) -> 3 ->절대값 matth.log(10,10) ->1 : math.log(a,b) b를 밑으로 하는 log a에 대한 로그 값 반환 math.log10() :10을 밑으로 하는..
-
문자열(String)Python/etc. 2020. 7. 28. 14:06
문자열(String) : 하나 또는 여러 개의 문자로 구성된 데이터형 문자들의 앞과 뒤에 쌍 따옴표(") 또는 단 따음표(')를 붙인다 위와 아래는 같은 의미이다. 파이썬에서 문자열은 C나 C++의 배열처럼 index로 접근할 수 있다. 인덱스는 '0'부터 시작한다. 마지막에 fruit[0:4]를 이용해서 출력하는 경우, 0번째인 인덱스부터 4번째 인덱스 앞인 e까지 출력한다. | 문자열 연결 연산자 : + 위의 예제처럼 문자열을 연결해 줄때 '+' 기호를 사용하기도 한다. | 문자열 반복 연산자 : * 위의 예제를 보면 '---'에 '*' 곱하기 연산자를 이용해서 '*5'를 해 주었더니 문자열이 5번 반복되어 15개가 출력되었다. | 문자열 길이 구하기 : len() 문자열의 길이를 구하기 위해서는 l..
-
기본 문법(연산자)Python/etc. 2020. 7. 28. 08:36
파이썬 쉘(Python Shell) : 직접 파이썬 명령을 입력하고 엔터 키를 누르면 바로 결과가 쉘 화면에 출력 MATLAB 처럼 계산기로 이용하기도 함 파이썬의 기본 문법인 연산자를 알아보자. 변수 a와 b를 각각 5와 10으로 입력해준다. 파이썬에서 변수명은 영문자, 숫자,밑줄(_)의 조합이 일반적이다. ex) type_1, apple, A,B,name1... **** 숫자로 시작하는 변수들은 오류가 발생한다. 1) 더하기 2) 빼기 3) 곱하기 4) 나누기 5) 나머지 연산 6) 나눈 후 소수점이하 절삭 4)번의 결과와 비교하면, 소수점 아래가 삭제된 것을 볼 수 있다. 7) 제곱구하기 제곱 연산자가 유용하게 쓰일 듯 하다. **** 변수명인 c만 입력해도 결과를 확인 할 수 있다. ㄲㅡㅌ