1. ÁбíÍƵ¼
1.1 ʹÓÃÁбíÍƵ¼µÃµ½µÑ¿¨¶û»ý
colors = ['white','black']
sizes = ['L','M','S']
t_shirt = [(color,size)for color in colors for size in sizes]
print(f"t_shirt={t_shirt}")
t_shirt=[('white', 'L'), ('white', 'M'), ('white', 'S'), ('black', 'L'), ('black', 'M'), ('black', 'S')]
1.2 ¹ýÂËÆ÷µÄÁбíÍƵ¼
symbol = "$¡é¡ê£¤€¡è"
list_0 = [ord(sym) for sym in symbol if ord(sym)> 163]
list_1 = [ord(sym) for sym in symbol]
print(f"list_0={list_0}")
print(f"list_1={list_1}")
1.3 ÁбíºÍÔª×é
ÁбíÊǿɱä±äÁ¿,¶øÔª×éÊDz»¿É±äÁ¿,ÔÚ½øÐбäÁ¿Ïà³ËµÄʱºò,ÁбíµÄIDµØÖ·²»±ä,¶øÔª×éµÄIDµØÖ·»á±ä
l = [1,2,3]
print(f"l={l}")
print(f"id(l)_before={id(l)}")
l *=2
print(f"l={l}")
print(f"id(l)after={id(l)}")
t =(1,2,3)
print(f"t={t}")
print(f"id(t)before={id(t)}")
t*=2
print(f"t={t}")
print(f"id(t)after={id(t)}")
- ½á¹û:ÁбíµÄIDû±ä,¶øÔª×éµÄID±äÁË
l=[1, 2, 3]
id(l)_before=139782399953568
l=[1, 2, 3, 1, 2, 3]
id(l)after=139782399953568
t=(1, 2, 3)
id(t)before=139782400381888
t=(1, 2, 3, 1, 2, 3)
id(t)after=139782521148368
2. ÁбíÇÐƬ
- ΪʲôÁбíºÍÇø¼äÔÚÇÐƬ¹ý³ÌÖÐÐèÒªºöÂÔ×îºóÒ»¸öÔªËØ;
(1)µ±Ö»ÓÐ×îºóÒ»¸öλÖÃÐÅÏ¢µÄʱºò,ÎÒÃÇ¿ÉÒÔ¿ìËÙ¿´³öÇÐƬºÍÇø¼äÀïÃæÓжàÉÙ¸öÔªËØ (2)µ±ÆðʼλÖö¼¿É¼ûµÄʱºò,ÎÒÃÇ¿ÉÒÔ¿ìËٵIJ鿴º¬¶àÉÙ¸öÔªËØ(end-start) (3)ÎÒÃÇ¿ÉÒÔ¸ù¾ÝÒ»¸öÔªËؽøÐÐÇиî,½«ÁÐ±í°´ÕÕÖ¸¶¨Î»ÖýøÐÐÒ»·ÖΪ¶þ
my_list=[0,1,2,3,4,5,6]
print(f"my_list={my_list}")
print(f"my_list[:3]={my_list[:3]}")
print(f"my_list[3:]={my_list[3:]}")
print(f"my_list[1:4]={my_list[1:4]}")
|