3 回答

TA貢獻1786條經驗 獲得超11個贊
1 2 3 4 5 6 7 8 9 | # -*- coding: cp936 -*- temp=input("猜猜數字") guess=int(temp) if guess==8: print"你是蛔蟲嗎" print"哼,中了" else: print"錯了," print"游戲結束!" |
input() 和int()都是內建函數,帶括號。

TA貢獻1963條經驗 獲得超6個贊
def get_year_count():
result = dict()
for k, v in Beatles_Discography.items():
if result.get(v, None) is None:
result[v] = 1
else:
result[v] += 1
result = sorted(result.iteritems(), lambda x:x[1], reverse=True)
return result
def get_the_most(the_list):
result = list()
temp = 0
for the_tuple in the_list:
if temp == 0:
temp = the_tuple[1]
result.append(the_tuple[0])
elif temp == the_tuple[1]:
result.append(the_tuple[0])
else:
break
return result
if __name__ == "__main__":
the_list = get_year_count()
result = get_the_most(the_list)
print(result)

TA貢獻2036條經驗 獲得超8個贊
字符串是單個字符的有序列表。你可以做測試,定義一個字符串,可以使用list方式逐個輸出字符。
字符編碼是字符在計算機內存中的表示方式。計算機只識別二進制數,而字符是二進制數編碼的顯示圖形,每個字符其實對計算機來說就是一個點陣圖形。不同的編碼對同一個字符的二級制表示方式可能不同,比如utf-8和GBK。
變量是內存數字的地址表示,先定義一個變量,那么腳本在讀取執行過程中遇到它就在內存中保存變量的內容,并把該數據內存的首地址給變量。(當然還要保存數據類型和長度等)
變量名就是變量的名字,同一個內存地址可以有不同的變量名。它是一個標號。
str表示變量的類型,也就是class。它是字符型。在python中沒有char與str之分,因為字符串是單個字符的有序列表。
a = '我是中國'
當腳本執行到上面時,在內存中寫入字符串”我是中國“,然后把首地址,字符類型,長度(等)用a來表示。
如果可以的話,可以刻使用python進行debug,然后你可以詳細的看清楚變量都有什么內容。python和其他語言沒有太大區別,無非就是組織形式,語法變化。
- 3 回答
- 0 關注
- 799 瀏覽
添加回答
舉報