-
파이썬을 배워 봅시다. 파이썬의 기본 데이터 타입 (1)사회 2024. 9. 21. 09:16728x90반응형
제목: 파이썬 초보자를 위한 기본 개념과 예제 (Part 2)
지난 글에서는 파이썬의 기초적인 개념과 환경 설정에 대해 다루었습니다.
이번 글에서는 파이썬의 데이터 타입, 제어문, 함수 등의 내용을 좀 더 구체적으로 다루며,
실습 예제를 통해 이해를 도울 것입니다.
차근차근 따라오시면, 누구나 쉽게 파이썬을 배울 수 있습니다.
파이썬의 기본 데이터 타입
파이썬에는 다양한 데이터 타입이 존재합니다.
이들을 잘 이해해야 프로그램에서 다루는 값들을 올바르게 처리할 수 있습니다.
정수 (int): 정수는 소수점이 없는 숫자를 의미합니다.
a=10
print(type(a)) # < class ' int '>
실수 (float): 소수점이 포함된 숫자를 나타냅니다.
b = 10.5
print(type(b)) # < class 'float'>
문자열 (str): 문자열은 글자들의 나열입니다.
파이썬에서는 작은따옴표(')나 큰따옴표(")로 문자열을 나타낼 수 있습니다.
c = "Hello"
print(type(c)) # < class ' str ' >
불리언 (bool): 참(True) 또는 거짓(False) 값을 나타내는 데이터 타입입니다
. d = True
print(type(d)) # < class ' bool ' >
리스트와 딕셔너리: 필수 데이터 구조
리스트: 여러 개의 값을 순서대로 담을 수 있는 자료구조입니다.
my_list = [1, 2, 3, 4, 5]
print(my_list [0]) # 1
파이썬에서는 데이터를 효율적으로 다루기 위해 다양한 자료 구조를 제공합니다.
그중에서도 리스트와 딕셔너리는 가장 많이 사용되는 자료구조입니다.
딕셔너리: 키-값 쌍으로 데이터를 저장하는 자료 구조입니다.
my_dict = {"name": "john", "age": 30}
print(my_dict ["name"]) # john
조건문: 프로그램의 흐름을 제어하는 방법파이썬에서
조건문은 프로그램의 흐름을 제어하는 중요한 기능을 합니다.
조건에 따라 코드를 다르게 실행할 수 있도록 도와줍니다.
if 문: 조건이 참일 때만 실행되는 코드 블록을 정의합니다.
x =10
if x > 5:
print("x는 5보다 큽니다.")
else 문: if 문의 조건이 거짓일 때 실행됩니다.
if x < 5: print("x는 5보다 작습니다.")
else:
print("x는 5보다 크거나 같습니다.")
elif 문: 여러 조건을 추가할 때 사용됩니다.
if x > 10:
print("x는 10보다 큽니다.")
elif x=10:
print("x는 10입니다.")
else:
print("x는 10보다 작습니다.")
728x90반응형'사회' 카테고리의 다른 글
파이썬을 배워 봅시다. 파이썬 기초: 리스트와 함수 쉽게 배우기(1) (0) 2024.09.21 파이썬을 배워 봅시다. 파이썬의 기본 데이터 타입(2) (0) 2024.09.21 AI로 집에서 부업 하는 방법, AI 기반 번역 및 통역에 대하여 배웁니다.(3) (0) 2024.09.03 AI로 집에서 부업 하는 방법, AI 기반 번역 및 통역에 대하여 배웁니다.(2) (14) 2024.09.03 AI로 집에서 부업 하는 방법, AI 기반 번역 및 통역에 대하여 배웁니다.(1) (2) 2024.09.03