新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:兩道簡單卻實用的python面試題
題目一:python中String類型和unicode什么關(guān)系

成都創(chuàng)新互聯(lián)公司主要從事網(wǎng)頁設(shè)計、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機版網(wǎng)站建設(shè))、響應(yīng)式網(wǎng)站建設(shè)、程序開發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、微信小程序開發(fā)等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站設(shè)計、成都做網(wǎng)站、網(wǎng)站設(shè)計、網(wǎng)絡(luò)營銷經(jīng)驗,集策劃、開發(fā)、設(shè)計、營銷、管理等多方位專業(yè)化運作于一體。
整理答案:string是字節(jié)串,而unicode是一個統(tǒng)一的字符集,utf-8是它的一種存儲實現(xiàn)形式,string可為utf-8編碼,也可編碼為GBK等各種編碼格式
題目二:不用set集合方法,去除列表中的重復(fù)元素
方法一:
List=['b','b','d','b','c','a','a'] print "the list is:" , List if List: List.sort() last = List[-1] for i in range(len(List)-2, -1, -1): if last==List[i]: del List[i] else: last=List[i] print "after deleting the repeated element the list is : " , List
方法二:使用列表綜合
l1 = ['b','c','d','b','c','a','a'] l2 = [] [l2.append(i) for i in l1 if not i in l2] print l2 題目三:實現(xiàn)斐波那契(Fibonacci)數(shù)列 方法一:遞歸 def fibonacci2(n): if n == 1 or n == 2: return 1 else: return fibonacci2(n-1) + fibonacci2(n-2)
方法二:迭代
def fibonacci(n): if n == 1 or n == 2: return 1 nPre = 1 nLast = 1 nResult = 0 i = 2 while i < n: nResult = nPre + nLast nPre = nLast nLast = nResult i += 1 return nResult print fibonacci(5)
名稱欄目:創(chuàng)新互聯(lián)Python教程:兩道簡單卻實用的python面試題
本文網(wǎng)址:http://www.5511xx.com/article/djgesoi.html


咨詢
建站咨詢
