Python learning path: day4; python path: day4

Source: Internet
Author: User

Python learning path: day4; python path: day4

Some common built-in functions:

Built-in function 1:

# Callable () # Check whether the function can be called. True and Falsedef f1 () are returned: pass # f1 () # f2 = 123 # f2 () can be called () # This cannot be called print (callable (f1) # It can be called print (callable (f2) # It cannot be called TrueFalse
Callable ()
# View the corresponding ascii code # ord () convert ASCII to a number # chr (), on the contrary, convert the number to ASCIIr = chr (65) print (r) # An = ord ("a") print (n) #97A97
Chr () and ord ()
# Random verification code import random # Add random verification code module li = [] for I in range (6): # loop temp = random. randrange (65, 91) # Return a random number c = chr (temp) in the set of the specified incremental base # convert the number to ASCII, which is originally a number, so convert it to uppercase letters, because the ASCII value of-91 is an uppercase letter li. append (c) # add each converted ascii to the list result = "". join (li) # Use the join method to convert the list to print (result) # random output at a time # input_li = input ("input li:") # if input_li = result: # print ("successfully logged on") # The following is a modified version # v2. The modified version can contain random numbers import randomli = [] for I in range (6): r = random. randrange (0, 4) # returns a random number if r = 2 or r = 4: # if the returned random number is equal to 2 or 4, let him continue with the next operation num = random. randrange (0, 10) li. append (str (num) # Add randomly generated values to the li list using strings. else: temp = random. randrange (65, 91) c = chr (temp) li. append (c) result = "". join (li) print (result) DYHVPI2QMTCM
Generate random Verification Code

 

Built-in function 2:

 

 

Last Update Time: 2017-11-30-18:43:02

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.