Skip to content
Snippets Groups Projects
Commit a624ae81 authored by KimMinSeob's avatar KimMinSeob
Browse files

Upload New File

parent 4133e6b7
No related branches found
No related tags found
No related merge requests found
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> #튜플 자료형
>>> t1=()
>>> t2=(1,)
>>> t3=(1,2,3)
>>> t4=1,2,3
>>> t5=('a','b',('c','d'))
>>> type(t1)
<class 'tuple'>
>>> type(t2)
<class 'tuple'>
>>> type(t3)
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
ype(t3)
NameError: name 'ype' is not defined
ty
>>> type(t3)
<class 'tuple'>
>>> type(t4)
<class 'tuple'>
>>> type(t5)
<class 'tuple'>
>>> t=(1)
>>> type(t)
<class 'int'>
>>> #튜플의 요소가 1개일떄는 반드시 ,를 붙여줘야한다.
>>> #튜플과 리스트의 차이는 요소를 변경시킬수 있느냐 없느냐의 차이이다.
>>> #튜플은 값을 변경할 수 가없다.
>>>
>>> t1=(1,2,'a','b')
>>> del t1[0]
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
del t1[0]
TypeError: 'tuple' object doesn't support item deletion
>>> #튜플은 요소를 지울수도없다.
>>> t1[0]
1
>>> t1[0] = 2
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
t1[0] = 2
TypeError: 'tuple' object does not support item assignment
>>> #인덱싱
>>> t1=(1,2,'a','b')
>>> t1[2]
'a'
>>> t1[3]
'b'
>>> #슬라이싱
>>> t1[1:]
(2, 'a', 'b')
>>> t1[:2]
(1, 2)
>>> #튜플 더하기
>>> t2=(3,4)
>>> t1+t2
(1, 2, 'a', 'b', 3, 4)
>>> t1 * 3
(1, 2, 'a', 'b', 1, 2, 'a', 'b', 1, 2, 'a', 'b')
>>> #튜플 연습문제
>>> # 숫자 3만을 요소로 가지는 튜플을 작성하여라.
>>> t=(3)
>>> type(t)
<class 'int'>
>>> t1=(3,)
>>> type(t1)
<class 'tuple'>
>>> #튜플에 요솣추가.
>>> t1=(1,2,3)
>>> t1.append(4)
Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
t1.append(4)
AttributeError: 'tuple' object has no attribute 'append'
>>> t1=[1,2,3]
>>> type(t1)
<class 'list'>
>>> t1.append(4)
>>> t1
[1, 2, 3, 4]
>>> t2=(1,2,3)
>>> t3=(4,)
>>> t4=t2+t3
>>> t4
(1, 2, 3, 4)
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment