본문 바로가기

컴퓨터/Python

Python operator 연산자 ▒ 산술 + 더하기 - 빼기 * 곱하기 / 실수 나누기 // 정수 나누기 % 나머지 ** 거듭제곱 파이썬엔 증감 연산자가 없다. ▒ 관계 왼쪽이 오른쪽보다 크면 1, 작거나 같으면 0 = 왼쪽이 오른쪽보다 크거나 같으면 1, 작으면 0 == 두 값이 같으면 1, 다르면 0 != 두 값이 다르면 1, 같으면 0 ▒ 논리 a = True b = False # and operator c = a and b print("a and b:", c) # or operator c = a or b print("a or b:", c) # not operator c = not a print("not a:", c)
Python list | 파이썬 배열 ▒ 정의 # empty list arr = [] # list with elements arr = [1, 2, 3, 4, 5] # list with different data types arr = [1, "two", 3.14, True] 배열의 요소를 정의하지 않고 길이만 지정할 수는 없다. 그런 경우 아래와 같은 방법을 사용할 수는 있다. arr = [None, None] ▒ 길이 len(array) ▒ 요소에 접근 arr[0] = 1 ▒ 요소 추가 >>> my_list = [1, 2, 3] >>> my_list.append(4) >>> print(my_list) [1, 2, 3, 4] >>> my_list = [1, 2, 3] >>> my_list.extend([4, 5, 6]) >>> print(my..
Python conditions | 파이썬 조건문 ▒ if-else x = 10 if x > 0: print("x is positive") else: print("x is negative")
Python loop | 파이썬 반복문 ▒ while count = 1 while count
Python standard input output | 파이썬 표준 입출력 name = input("What is your name? ") print("Hello, " + name) print("Hello, world!", end="") #출력 마지막의 줄바꿈 문자를 ""로 변경해서 줄바꿈 방지. 다른 문자도 사용 가능