Skip to Content
Python 소개, 제 2판
book

Python 소개, 제 2판

by Bill Lubanovic
May 2025
Intermediate to advanced
630 pages
8h 17m
Korean
O'Reilly Media, Inc.
Content preview from Python 소개, 제 2판

2장. 데이터 유형, 값, 변수 및 이름

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

좋은 이름은 큰 재물보다 선택받아야 합니다.

잠언 22:1

컴퓨터의 모든 것은 내부적으로는 비트의시퀀스에 불과합니다( 부록 A 참조). 컴퓨팅의 통찰력 중 하나는 이러한 비트를 다양한 크기와 유형의 데이터(숫자, 텍스트 문자) 또는 컴퓨터 코드 자체로 원하는 방식으로 해석할 수 있다는 것입니다. 우리는 Python을 사용하여 이러한 비트의 청크를 다양한 목적으로 정의하고 CPU와 주고받을 수 있도록 합니다.

Python의 데이터 유형과포함할 수 있는 값부터 시작하여 데이터를 리터럴 값과 변수로 표현하는 방법을 살펴봅니다.

Python 데이터는 객체입니다.

컴퓨터의 메모리를 일련의 긴 선반으로 시각화할 수 있습니다. 이러한 메모리 선반의 각 슬롯은 폭이 1바이트(8비트)이고 슬롯은 0(첫 번째)부터 끝까지 번호가 매겨집니다. 최신 컴퓨터는 수십억 바이트(기가바이트)의 메모리를 가지고 있으므로 선반은 거대한 가상의 창고를 채울 수 있습니다.

Python 프로그램은 운영 체제에 의해 컴퓨터의 일부 메모리에 대한 액세스 권한을 부여받습니다. 해당 메모리는 프로그램 자체의 코드와 프로그램에서 사용하는 데이터에 사용됩니다. 운영 체제는 프로그램이 어떻게든 권한을 얻지 않고는 다른 메모리 위치를 읽거나 쓸 수 없도록 보장합니다.

프로그램은 비트가 어디에 (메모리 위치) 있는지, 어떤 (데이터 유형) 것인지 추적합니다. 컴퓨터에서는 모두 비트일 뿐입니다. 같은 비트도 어떤 유형인지에 따라 다른 의미를 갖습니다. 동일한 비트 패턴은 정수 65또는 텍스트 문자 A 를 나타낼 수 있습니다.

유형에 따라 다른 비트 수를 사용할 수 있습니다. '64비트 머신'에 대해 읽었을 때 이는 정수가 64비트(8바이트)를 사용한다는 의미입니다.

일부 언어는 이러한 원시 값을 메모리에 넣고 뽑아 크기와 유형을 추적합니다. 이러한 원시 데이터 값을 직접 처리하는 대신 Python은 각 데이터 값(부울, 정수, 정수, 문자열, 심지어 큰 데이터 구조, 함수 및 프로그램)을 메모리에서 객체로 래핑합니다. Python에서 자신만의 객체를 정의하는 방법에 대해서는 전체 장(10장)이 있지만 여기서는 기본 내장 데이터 유형을 처리하는 객체에 대해서만 이야기합니다.

메모리 선반 비유를 사용하면 그림 2-1과 같이 객체를 선반의 공간을 차지하는 가변 크기 상자로 생각할 수 있습니다. Python은 이러한 객체 상자를 만들어 선반의 빈 공간에 넣고 더 이상 사용하지 않을 때 제거합니다.

inp2 0201
그림 2-1. 객체는 상자와 같으며, 이 객체는 값이 있는 정수입니다. 7

Python에서 객체는 최소한 다음을 포함하는 데이터 덩어리입니다: ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python 학습, 제 5판

Python 학습, 제 5판

Mark Lutz
fastai와 파이토치가 만나 꽃피운 딥러닝

fastai와 파이토치가 만나 꽃피운 딥러닝

박찬성, 김지은, 제러미 하워드, 실뱅 거거

Publisher Resources

ISBN: 9798341653764