Coding/Python

[python]bool 자료형/함수, 논리연산자

후__아 2024. 3. 14. 16:09

※ boolean

bool 자료형

True, False

 

※ bool 함수

bool(값이 있는 변수) == True

int(bool(True))) == 1

# 백준 2753
a = int(input())
if a % 4 == 0:
  if a % 100 == 0:
    if a % 400 == 0: print(1)
    else: print(0)
  else: print(1)
else: print(0)

# bool
a = int(input())
print(int((not a % 4) and (a % 100 or not a % 400)))

# 프로그래머스 n의 배수
def solution(num, n):
    return 1 if num % n == 0 else 0
    # 다른 풀이
    # return int(num % n == 0)
    # return 1 if not(num % n) else 0
    
# 공배수
def solution(number, n, m):	# number가 n과 m의 공배수일 때 1
    return 1 if (not(number % n)) & (not(number % m)) else 0
    # return int((number % n) == 0 and (number % m) == 0)	# 다른 풀이

 

 

'Coding > Python' 카테고리의 다른 글

[python]대소문자 함수-upper, lower, swapcase, isupper  (0) 2024.04.16
[python]시간/분/초 변환  (0) 2024.03.18
[python]sum  (0) 2024.03.14
[python]문자열 format, raw string  (0) 2024.03.14
[python]map 함수  (0) 2024.03.14