- 튜플(tuple)
- 리스트
- 사전자료형(자바에서는 map)
- 각 데이터 타입별 변환
튜플(tuple)#
def magu_print(x, y, *rest):
print x, y, rest;
print len(rest);
for i in rest:
print i;
r = (3,4,5,6,7,8);
magu_print(1, 2, r);
magu_print(1, 2, 3, 4, 5, 6, 7, 8);
|
리스트#
list=[1,2,3,4,5,6];
print len(list);
for i in list:
print i;
|
사전자료형(자바에서는 map)#
a={'1':'abc', '2':'test', '3':'1111'};
print a;
for i in a:
print i;
print a[i];
print a.has_key('1');
print a.has_key('4');
|
각 데이터 타입별 변환#
- 숫자형으로 변환
- int(1.1) -> 1
- float(1.1) -> 1.1
- long(1.1) -> 1L
- 문자형으로 변환
- str()
- repr() (-> eval() -> repr())
- 문자변환
- chr(100) ('d' 출력)
- ord('b') (98 출력)
- 진수 변환
- int('60', 16) (16진수 60을 10진수로 변환, 96 출력)
- int('144', 8) (8진수 144를 10진수로 변환, 100 출력)
- int('10111', 2) (2진수 10111을 10진수로 변환, 23 출력)
- hex(100) (10진수 100을 16진수로 변환, '0x64' 출력)
- oct(100) (10진수 100을 8진수로 변환, '0144' 출력)
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'ko_KR.UTF-8'
>>> print locale.format("%d", 10030405, 1)
10,030,405
|
Add new attachment
Only authorized users are allowed to upload new attachments.
«
This page (revision-6) was last changed on
16-Nov-2008 20:40 by DongGukLee