프리렉 - FREELEC
http://freelec.co.kr/book/catalogue_view.asp?UID=134
이강성저
리스트의 슬라이싱은 새로운 리스트 객체를 만들고 원래 리스트의 참조를 복사해오는 것으로 앝은 복사와 동일하다.
L = [1,2,3,4,5]
L1 = L[:]
깊은 복사에 복사되는 객체는 리스트, 튜플, 사전과 같은 복합 객체이다. 문자열, 수치연산등과 같은 객체들은 복사되지 않는다.
import copy
x = ([500,1000], 2000)
y = copy.deepcopy(x)
print (id(x) != id(y))
print (id(x[0]) != id(y[0]))
print (id(x[1]) == id(y[1]))
1단계 복합 객체로 이루어진 경우의 깊은 복사와 앝은 복사는 동일한 방식으로 복사된다.
x = [500, 1000]
y1 = copy.deepcopy(x)
y2 = copy.copy(x)
s = '4124.8963'
dm = float(s) # 수치로 변환
dm
deg = int(dm / 100) # 각만 분리
deg
minute = dm - deg*100 # 분 분리
minute
min = int(minute)
min
sec = (minute % 1) * 60
sec
round(sec)
import math, cmath
rad = [math.radians(d) for d in range(0, 361, 10)]
for d in range(0, 361, 10):
r = math.radians(d)
ejx = cmath.e ** complex(0, r)
print ('deg={:3d} x={:.4f} rad e(jx)={:16.4f}'.format(d, r, ejx))
# 참고 외부 모듈 numpy를 이용한 방법
import numpy as np
deg = np.arange(0, 361, 10)
rad = np.radians(deg)
ejx = np.power(np.e, 1j*rad)
for e in ejx:
print ('e(jx)={:16.4f}'.format(e))
s = '세종대왕의 한글'
for c in s:
print ('{:3s} {:5d} {:6s}'.format(c, ord(c), hex(ord(c))))
s = '세종대왕의 한글'
b = s.encode('utf-8')
b
import binascii
binascii.hexlify(b)
n = 123456789
format(n, ',')
'{:,}'.format(n)