YUYANE

Python/ Sequence Type (list, dictionary) 본문

Programming Languages/PYTHON

Python/ Sequence Type (list, dictionary)

YUYA 2020. 12. 14. 13:55

Sequence Type(열거형)

  1) list

   - 많은 값을 하나의 list에 저장해보자

     days = ["Mon","Tue","Wed","Thur","Fri"]

     print("Mon" in days) = True

     print(days[3]) = Thur

     len(days) = 5

   - 다양한 타입 저장 가능

   something =["tnjkd", True, 12, None]

   - mutable(변경 가능)

     days.append("Sat")

    ["Mon","Tue","Wed","Thur","Fri", "Sat"]

 

  2) tuple

     days = ("Mon","Tue","Wed","Thur","Fri")

   - immutable

 

 3) Dictionary

  - key : value 로 이루어진 Mapping 타입이다.

  - nico = {

    "name": "Nico",

    "age": 29,

    "Korean": True,

    "fav_food": ["Kimchi", "Sashimi"]

   }

   - print(nico["name"])=Nico

   - 새로운 값을 추가하고 싶을 때

    nico["handsome"] = True

   - Mutable

 

 

참고 예제

people = [
 {'name':'jun', 'age':30},
 {'name':'jun', 'age':30},
 {'name':'jun', 'age':30},
 ]

 

 

**Python 문서

docs.python.org/3/library/

 

The Python Standard Library — Python 3.9.1 documentation

The Python Standard Library While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes some of the opt

docs.python.org

**

'Programming Languages > PYTHON' 카테고리의 다른 글

Python / 반복문  (0) 2020.12.16
Python / 조건문  (0) 2020.12.16
Python/ function  (0) 2020.12.15
Python/ Functions  (0) 2020.12.14
Python/ 변수에 저장할 수 있는 타입  (0) 2020.12.14
Comments