Python-built-in Functions 4

Source: Internet
Author: User
Tags ord

Name= "one"

‘‘‘
Bin ()
Oct ()
Hex ()
Bytes ()
ASCII ()
Any ()
All ()
ABS ()
BOOL ()
STR ()
Dict ()
List ()
Callable () Determines whether it can be called, most of which are used for functions
Char () converts the number of ASCII codes to characters
Ord () Converts the character to the corresponding ASCII number
‘‘‘

‘‘‘
Hello everyone, I am chi lei, and then I will give you a walkthrough of using Python to generate verification code functions

The function to Use:
CHR () generates one character for a single piece of data
Modules used
Random Stochastic module

We know that a-z is from 65-90

‘‘‘

# import Random

‘‘‘
So we can convert it into Characters.

Let's say we generate a 6-digit verification code.

We're just using strings to Connect.

We can use the list, of Course.

List is also possible, but there is a problem, we generate the validation through the data, how to deal with it

So we can generate a code with numbers and letters, Thank you for Watching.

See:

‘‘‘

‘‘‘
code=[]

For I in range (6):

Num=random.randrange (0,5) #随便定义一个范围
If num ==0 or num ==4:
alpha= CHR (random.randrange (65,90))
Code.append (alpha)
Else
Digital=random.randrange (0,10)
Code.append (str) #但是字符串分隔的话只能是一个数字, We want to convert data into strings

string= "". Join (code)
Print (string,type (string))

‘‘‘

‘‘‘

Compile () #将一个字符串或者是文件进行编译
EXEC () #执行complie后的结果
Eval () #将一个数字的表达式进行执行

‘‘‘


# s= "print (' aaaaaaaaaaaa ')"
# eval (s)


# s= "a.py"
# r=compile (s, ' exec ')
# exec (r)

‘‘‘

Dir () See what specific features a class provides
Help () read the original code of a class
Divmod two parameters to divide, the result is an array, (quotient, remainder)
Isinstance () is used to determine whether an object is an instance of a class
Filter ()
Map ()

‘‘‘
# Print (dir (list))
# Help (dict)

# S,y=divmod (100,9)
# Print (s,y)

# s= "cdinniet"
# if Isinstance (s,str):
# Print (' Yes ')
# else:
# Print ("no")

# def one (a):
# If a > 22:
# return True
#
# Res=filter (one,[11,22,33,44,55])
#
# Print (list (RES))

# def one (x):
# return X**3
#
# Re=map (one,[1,2,3])
#
# Print (list (re))
#
#
# map (one,)


‘‘‘
1.lambda declares an anonymous function, and automatically gives you a return value
2.map ()
3.float ()
4.globals ()
5.locals ()
6.input ()
7.print ()
8.int ()
9.int ()
10.len ()
11.open ()
12.bin
13.oct ()
14.hex ()
15.tuple ()
16.sum ()
17.set ()
18.min
19.ord ()
20.CHR ()
21.isinstance ()
22.bool ()
23.bytes ()
24.eval ()
25.compile ()
26.exec ()
27.type ()
29.filter ()
30.map ()
31.dir ()
32.divmod ()
33.range ()
34.all ()
35.any ()
36.slice ()
37.next ()
38.hash () #将一个长值转换为一个定长的值 commonly used in dictionaries to convert long keys to fixed-length values

Min ()
Max ()
Sum ()
Reversed () =list.reverse () Flip
Round () Rounding
Slice () slices
Sorted () List Sort =li.sort ()
Zip ()


‘‘‘

# result =filter (lambda a:a>30,[11,22,33,44,55])
# Print (list Result)


# Result=map (lambda a:a+100,[11,22,33])
# Print (list Result)


# string= "feineintitnit niet neit Neit nei"
# Print (hash (string))


# string= "Shup"
# s=bytes (string,encoding= ' Utf-8 ')
# Print (len (S))

# for I in "li jie":
# Print (i)

# for K,v in enumerate (' li Jie '):
# Print (k,v)

# dic={"name": "zhilei", ' age ': 10}
# for A in enumerate (dic):
# for I in a:


# li=[3,20,6,9]
# li= (3,422,44)
# li2=sorted (li) #返回另外的一个列表
# Print (li2)


# li=[' name ', ' Age ']
# li1=[' Zhilei ', 10]
# Li2=zip (li,li1)
# Print (list (li2))


# li={"name", ' Age '}
# li1={' Zhilei ', 10}
# Li2=zip (li,li1)
# Print (list (li2))

# li={' name ': ' Zhilei ', ' age ': 10}
# li1={' name1 ': "zhilei1", ' Age1 ': 11}
# Li2=zip (li,li1)
# Print (list (li2))


# s= "nicenitneti"
# A=slice (0,3) #切片, start stop but does not include stop
# Print (s[a])


# dep= "monitoring center"
# Print (globals ())


# def one ():
# desc= "people's Republic of china"
# Print (locals ())
# One ()
# Print (locals ())

# R=round (1.3)
# Print (r)


# li=[25,67,11]
# sorted (li)
# Print (li)

# r=compile ("print (' Monitor Center ')", ' <string> ', ' exec ')
# exec (r)


# Print (eval ("3+6"))

Python-built-in Functions 4

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.