Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 깊은 복사
- 내부클래스
- Inbound
- identityHashCode
- Stream
- has-a
- shebang
- arraycopy
- 스트림
- Wrapper class
- down casting
- 얕은 복사
- singletone
- parameter group
- 셔뱅
- 파이참
- finalize
- access modifier
- 자바
- constructor
- dbeaver
- pycharm
- Java
- node.js
- generic programming
- Up Casting
- 엔드포인트
- public static final
- extends
- lambda
Archives
- Today
- Total
٩(๑•̀o•́๑)و
list & tuple 본문
#1. list : 요소의 수정, 삭제, 추가 가능
#! /usr/local/bin/python3.8
listA = []
listB = list()
print(listA)
print(listB)
listA = [1, 2, 3, 4]
listB = ['str', 1, 0.2]
print(listA)
print(listB)
====Result======
[]
[]
[1, 2, 3, 4]
['str', 1, 0.2]
#! /usr/local/bin/python3.8
listA = list(range(5))
listB = list(range(5, 9))
listC = list(range(10, 0, -2))
print(listA)
print(listB)
print(listC)
=====Result====
[0, 1, 2, 3, 4]
[5, 6, 7, 8]
[10, 8, 6, 4, 2]
a = [25, 31, 16, 50]
print('#1. ')
for i in a:
print(i)
print('\n#2. idx, value')
for idx, value in enumerate(a):
print(idx, value)
print('\n#3. idx, value, start')
for idx, value in enumerate(a, start=1):
# for idx, value in enumerate(a, 1):
print(idx, value)
print('\n#4. range')
for i in range(len(a)):
print(i, a[i])
print('\n#5. while')
i = 0
while i < len(a):
print(i, a[i])
i += 1
====Result====
#1.
25
31
16
50
#2. idx, value
0 25
1 31
2 16
3 50
#3. idx, value, start
1 25
2 31
3 16
4 50
#4. range
0 25
1 31
2 16
3 50
#5. while
0 25
1 31
2 16
3 50
#2. tuple : read only
#! /usr/local/bin/python3.8
tupleA = (1, 2, 3)
tupleB = 4, 5, 6
tupleC = 'str', 4, 0.2
print(tupleA)
print(tupleB)
print(tupleC)
====Result====
(1, 2, 3)
(4, 5, 6)
('str', 4, 0.2)
#! /usr/local/bin/python3.8
num1 = (1)
tupleA = (2, )
num2 = 3
tupleB = 4,
print(num1)
print(tupleA)
print(num2)
print(tupleB)
====Result====
1
(2,)
3
(4,)
#! /usr/local/bin/python3.8
tuple1 = tuple(range(5))
tuple2 = tuple(range(3, 6))
tuple3 = tuple(range(1, 10, 2))
tuple4 = tuple(range(20, 15, -1))
print(tuple1)
print(tuple2)
print(tuple3)
print(tuple4)
====Result====
(0, 1, 2, 3, 4)
(3, 4, 5)
(1, 3, 5, 7, 9)
(20, 19, 18, 17, 16)
#3. Examples
#! /usr/local/bin/python3.8
list1 = [1, 2, 3]
tuple1 = tuple(list1)
print(tuple1)
tuple2 = (4, 5, 6)
list2 = list(tuple2)
print(list2)
====Result====
(1, 2, 3)
[4, 5, 6]
#! /usr/local/bin/python3.8
list1 = list("hello")
tuple1 = tuple("world")
print(list1)
print(tuple1)
====Result====
['h', 'e', 'l', 'l', 'o']
('w', 'o', 'r', 'l', 'd')
#! /usr/local/bin/python3.8
a, b, c = [1, 2, 3]
print(a, b, c, sep=', ')
d, e, f = (4, 5, 6)
print(d, e, f, sep=', ')
x = list("abc") #list packing
c1, c2, c3 = x #list unpacking
print(c1, c2, c3, sep=', ')
y = (10, 20, 30) #tuple packing
num1, num2, num3 = y #tuple unpacking
print(num1, num2, num3, sep=', ')
=====Result====
1, 2, 3
4, 5, 6
a, b, c
10, 20, 30
'Python' 카테고리의 다른 글
sequence types - slice (0) | 2020.09.08 |
---|---|
sequence types (0) | 2020.09.08 |
input (0) | 2020.09.04 |
String (0) | 2020.07.28 |
Boolean (0) | 2020.07.28 |