python的學習之路day4,python之路day4

來源:互聯網
上載者:User

python的學習之路day4,python之路day4

一些常用的內建函數:

內建函數一:

# callable()#檢查函數是否能被調用,返回True、Falsedef f1():    pass# f1()#能被調用f2 = 123# f2()# 這個不能被調用print(callable(f1))  # 能被調用print(callable(f2))  # 不能被調用TrueFalse
callable()
# 查看對應的ascii碼# ord()把ASCII轉換成數字# chr()則相反,把數字轉換成ASCIIr = chr(65)print(r)  # An = ord("a")print(n)  # 97A97
chr() and ord()
#隨機驗證碼import random  # 加入隨機驗證碼模組li = []for i in range(6):  # 迴圈    temp = random.randrange(65, 91)  # 方法返回指定遞增基數集合中的一個隨機數    c = chr(temp)  # 把數字轉換成ASCII,原來為數字,所以轉換為了大寫字母,因為65-91對應的ASCII為大寫字母    li.append(c)  # 將每次轉換的ascii加入到列表中result = "".join(li)  # 用join方法把列錶轉換為字元print(result)  # 每次隨機輸出# input_li = input("input li:")# if input_li == result:#     print("登入成功")# 以下是修改版# v2,這個修改版可以隨機出現數字import randomli = []for i in range(6):    r = random.randrange(0, 4)  # 返回一個隨機數    if r == 2 or r == 4:  # 如果返回的隨機數等於2或者等於4的時候,讓他繼續下一步操作        num = random.randrange(0, 10)        li.append(str(num))  # 用字串的方式將隨機產生的值添加到li列表中    else:        temp = random.randrange(65, 91)        c = chr(temp)        li.append(c)result = "".join(li)print(result)DYHVPI2QMTCM
產生隨機驗證碼

 

內建函數二:

 

 

最後更新時間:2017-11-30-18:43:02

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.