Python 기본 데이터 타입 완벽 가이드
정수형 intPython의 정수형은 다양한 진법 변환과 비트 연산을 지원합니다.# 문자열을 정수로 변환
num_str = "456"
converted = int(num_str)
print(converted) # 456
# 앞에 0이 있는 경우 기본적으로 10진수로 해석
leading_zero = "0077"
result = int(leading_zero)
print(result) # 77
# 특정 진법에서 10진수로 변환
hex_val = "00FF"
oct_val = "0077"
print( ...
6월 7일 18:04에 게시됨
파이썬 함수 및 데이터 구조 활용 가이드
함수 정의와 호출
파이썬에서 함수는 def 키워드로 선언하며, 타입 힌트를 포함할 수 있다.
def calculate(x: int, y: int, multiplier: int = 1) -> int:
return (x + y) * multiplier
# 또는 타입 없이도 가능
def calculate(x, y, multiplier=1):
return (x + y) * multiplier
함수의 타입 정보는 calculate.__annotations__로 확인할 수 있다.
매개변수 전달 ...
5월 20일 03:03에 게시됨