Python
-
not, and, or 연산 순서Python 2023. 10. 27. 20:16
논리 연산자가 식 하나에 들어있으면 not, and,or 순으로 연산된다 not True and False or not False # 왼쪽과 같은 식이 있다면 (not True) and False or (not False) # not 연산을 먼저 해서 정리해준뒤 (False and False) or True # and 연산 시행 False or True # 마지막으로 or 연산을해준다 >> True 비교연산자와 논리 연산자가 섞여 있을 경우에는 1 == 1 and 1 != 1 # 논리연산자와 비교연산자가 함께 있을때는 (1 == 1) and (1 != 1) # 비교연산자를 먼저 한뒤 True and False # 논리 연산자를 처리해준다 >> False
-
print 함수 특징 - sep, endPython 2023. 10. 27. 19:57
1. print 함수는 여러 인자를 출력할때 문자 사이를 공백으로 띄어서 한 줄로 출력한다 2. sep 인자를 이용하면 인자들 사이를 sep에 지정된 문자 혹은 문자열로 구분하여 출력된다. sep 인자로 ' '를 사용할 경우 공백의 칸 수가 출력 결과에 영향을 주므로 주의해야 한다 3. end 의 디폴트 값은 \n이다. end를 어떻게 설정하냐에 따라 뒤이어 오는 print 문에 영향을 주므로 주의해야 한다 디폴트 값인 \n을 그대로 end 인자 값이 대체 하는 것이므로 출력이 중요한 상황에서는 주의해야 한다!
-
[Tkinter] geometry 함수Python/Tkinter 2023. 2. 15. 22:37
def wm_geometry(self, newGeometry=None): """Set geometry to NEWGEOMETRY of the form =widthxheight+x+y. Return current value if None is given.""" return self.tk.call('wm', 'geometry', self._w, newGeometry) geometry = wm_geometry geometry('widthxheight+x+y') 또는 geometry('widthxheight') 형태로 사용한다.
-
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만 입력해도 결과를 확인 할 수 있다. ㄲㅡㅌ