Python¿ª·¢Ñ§Ï°ÐèÒªÖªµÀµÄ¸ß¼¶¼¼ÇÉÕûÀí
2022-01-07µã»÷Á¿£º972
Python¿ª·¢ÖÐÓÐÄÄЩ¸ß¼¶¼¼ÇÉ£¿ÁбíÍƵ¼Ê½>>>chars=[cforcin'python']>>>chars['p','y','t','h','o','n']×ÖµäÍƵ¼Ê½>>>dict1={'a':1,'b':2,'c':3,'d':4,'e':5}>>>double_dict1={k:v*2for(k,v)indict1.items()}>>>double_dict1{'a':2,'b':4,'c':6,'d':8,'e':10}¼¯ºÏÍƵ¼Ê½>>>set1={1,2,3,4}>>>double_set={i*2foriinset1}>>>double_set{8,2,4,6}ºÏ²¢×Öµä>>>x={'a':1,'b':2}>>>y={'c':3,'d':4}>>>z={**x,**y}>>>z{'a':1,'b':2,'c':3,'d':4}¸´ÖÆÁбí>>>nums=[1,2,3]>>>nums[::][1,2,3]>>>copy_nums=nums[::]>>>copy_nums[1,2,3]·´×ªÁбí>>>reverse_nums=nums[::-1]>>>reverse_nums[3,2,1]PACKING/UNPACKING±äÁ¿½»»»>>>a,b=1,2>>>a,b=b,a>>>a2>>>b1¸ß¼¶²ð°ü>>>a,*b=1,2,3>>>a1>>>b[2,3]»òÕß>>>a,*b,c=1,2,3,4,5>>>a1>>>b[2,3,4]>>>c5º¯Êý·µ»Ø¶à¸öÖµ£¨ÆäʵÊÇ×Ô¶¯packing³ÉÔª×飩Ȼºóunpacking¸³Öµ¸ø4¸ö±äÁ¿>>>deff():...return1,2,3,4...>>>a,b,c,d=f()>>>a1>>>d4ÁбíºÏ²¢³É×Ö·û´®>>>"".join(["I","Love","Python"])'ILovePython'Á´Ê½±È½Ï>>>ifa>2anda<5:...pass...>>>if2...