Notice
Recent Posts
Recent Comments
«   2024/10   »
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 31
10-10 20:16
Archives
Today
Total
관리 메뉴

Developer_Neo

[python] 빈 문자열, 리스트, 사전, 튜플, 집합 만들기 본문

프로그래밍/Python

[python] 빈 문자열, 리스트, 사전, 튜플, 집합 만들기

_Neo_ 2022. 1. 16. 12:23
반응형

빈 문자열 만들기

  1. 빈따옴표 이용
  2. str()함수이용
#빈따옴표 이용
s=''
print(s)
# 결과->             
# 아무것도 안나옴
len(s) # 결과: 0
type(s) # 결과: <class 'str'>
>>> w = str( ) 
>>> print(w) 
>>> len(w) 
0
>>> type(w) 
<class 'str'>

빈 리스트만들기

  1. 빈 대괄호 이용
  2. list()함수이용
>>> a = []
>>> print(a)
[]
>>> type(a)
<class 'list'>

>>> b = list()
>>> print(b)
[]
>>> type(b)
<class 'list'>

 

빈 튜플만들기

  1. 빈 소괄호 이용
  2. tuple()함수이용
>>> a=()
>>> print(a)
()
>>> type(a)
<class 'tuple'>

>>> b=tuple()
>>> print(b)
()
>>> type(b)
<class 'tuple'>

 

빈 사전만들기

  1. 빈 중괄호 이용
  2. dict()함수이용
>>> a={}
>>> print(a)
{}
>>> type(a)
<class 'dict'>

>>> b=dict()
>>> print(b)
{}
>>> type(b)
<class 'dict'>

 

빈 집합만들기

  1. set()함수 이용 (사전과 구분되기 때문이다.)
>>> a=set()
>>> print(a)
set()
>>> type(a)
<class 'set'>
반응형
Comments