티스토리 뷰

List

많은 value 들을 열거할 때 사용하며 , 필요한 값을 불러내야 할 때 사용합니다

 

list를 생성하는 방법은 대괄호로 묶어주며 (  [  ]  ) ,  그 안의 값들을  콤마 (  ,  ) 로 나누어 줘야 합니다

 

 

리스트의 활용 방법들

출처 : https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range

Lists are mutable sequences, typically used to store collections of homogeneous items (where the precise degree of similarity will vary by application).

 

목록은 일반적으로 균질한 항목의 컬렉션을 저장하는 데 사용되는 변이 가능한 시퀀스입니다(여기서 응용 프로그램에 따라 유사성의 정밀도가 달라집니다.

 

-->> List 는 변경 가능한 타입 (mutable)

 

mutable 형식을 이용할 수 있음

 

 

Tuple

class tuple([iterable])

Tuples may be constructed in a number of ways:

튜플은 여러 가지 방법으로 구성될 수 있습니다.

 

사용 방법은 (  )  를 이용합니다

 

 

  • Using a pair of parentheses to denote the empty tuple: ()  // 
  • Using a trailing comma for a singleton tuple: a, or (a,)
  • Separating items with commas: a, b, c or (a, b, c)
  • Using the tuple() built-in: tuple() or tuple(iterable)

 

  • 괄호 쌍을 사용하여 빈 튜플을 나타냄: ()
  • 단일 톤 튜플에 대해 후행 쉼표 사용(a, 또는 (a,))
  • 쉼표로 항목 구분: a, b, c 또는 (a, b, c)
  • 기본 제공 튜플 사용: 튜플() 또는 튜플(수집 가능)

 

 

tuple 은 immutable 형식입니다

 

-->> 변경 불가능한 형식

 

아무도 변경할 수 없는 형식을 원할 때가 있는데 그때 tuple을 사용하면 된다 <리스트와 같지만 변경 불가능>

 

list 와 달리 이 기능들만 사용이 가능하다

 

 

 

그리고 sequence 타입이 아닌 mapping 타입인 Dict 타입이 있습니다

 

Dictionary

 

Mapping Types — dict

A mapping object maps hashable values to arbitrary objects. Mappings are mutable objects. There is currently only one standard mapping type, the dictionary. (For other containers see the built-in list, set, and tuple classes, and the collections module.)

A dictionary’s keys are almost arbitrary values. Values that are not hashable, that is, values containing lists, dictionaries or other mutable types (that are compared by value rather than by object identity) may not be used as keys. Numeric types used for keys obey the normal rules for numeric comparison: if two numbers compare equal (such as 1 and 1.0) then they can be used interchangeably to index the same dictionary entry. (Note however, that since computers store floating-point numbers as approximations it is usually unwise to use them as dictionary keys.)

Dictionaries can be created by placing a comma-separated list of key: value pairs within braces, for example: {'jack': 4098, 'sjoerd': 4127} or {4098: 'jack', 4127: 'sjoerd'}, or by the dict constructor.

 

매핑 개체는 해시 가능한 값을 임의 개체에 매핑합니다. 매핑은 변경할 수 있는 개체입니다. 현재 표준 매핑 유형인 사전이 하나만 있습니다. (다른 컨테이너의 경우 기본 제공 목록, 세트 및 튜플 클래스 및 컬렉션 모듈을 참조하십시오.)

사전의 키는 거의 임의의 값입니다. 해시할 수 없는 값, 즉 목록, 사전 또는 기타 변형 가능한 유형(객체 ID가 아닌 값으로 비교됨)을 포함하는 값을 키로 사용할 수 없습니다. 키에 사용되는 숫자 유형은 숫자 비교에 대한 일반적인 규칙을 따릅니다. 두 개의 숫자가 동일할 경우(1과 1.0 등) 두 숫자를 서로 교환하여 동일한 사전 항목을 색인화할 수 있습니다. 그러나 컴퓨터는 부동 소수점 숫자를 근사치로 저장하므로 이를 사전 키로 사용하는 것이 현명하지 않습니다.

사전은 쉼표로 구분된 키 목록(예: {'jack': 4098, 'sjoerd': 4127} 또는 {4098: 'jack', 4127: 'sjoerd'})을(를) 배치하거나 dict 생성자에 의해 만들 수 있습니다.

 

 

 

기본적으로 key 와 value 로 이루어진 형식입니다

 

사용 방법은  {  }  를 이용합니다

 

me = {"name" : "GilPOP" ,  "age" : "26" ,  "koeran" : "True",  "fav_food" : ["Kimchi" , "meat"] }

방식을 이용하면 되겠습니다

 

dictionary 방식에 list , tuple ,dictionary 방식을 안에 넣을 수 있습니다  ,

이를 제외하고도 다양한 타입을 이용할 수 있습니다

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함