#Python撲克牌的4種花色,撲克牌洗牌_2
import random
a1=[];a2=[];b1=[];b2=[];c1=[];c2=[];d1=[];d2=[]
card=random.sample(range(1,53),52)
for i in range(52):
if card[i]//13==1:f=”?心” #從word複製花色的圖形進去
elif card[i]//13==2:f=”?鑽”
elif card[i]//13==3:f=”?鏟”
else :f=”?花”
if card[i]%13== 0:p=”A”
elif card[i]%13==10:p=”J”
elif card[i]%13==11:p=”Q”
elif card[i]%13==12:p=”K”
else :p=str(card[i]%13+1) # %求餘數
if i%4 ==0:
a1.append(f)
a2.append(p)
if i%4 ==1:
b1.append(f)
b2.append(p)
if i%4 ==2:
c1.append(f)
c2.append(p)
if i%4 ==3:
d1.append(f)
d2.append(p)
print(“=一=*=二=*=三=*=四=”)
for j in range(13):
print(“%s%-2s “%(str(a1[j]),str(a2[j])),end=”*”)
print(“%s%-2s “%(str(b1[j]),str(b2[j])),end=”*”)
print(“%s%-2s “%(str(c1[j]),str(c2[j])),end=”*”)
print(“%s%-2s “%(str(d1[j]),str(d2[j])))


輸出結果:








![Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件) Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()] Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()]](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2024/11/20241123194900_0_5218de.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言