首页 > 代码库 > 2016/11/30 (内置函数)

2016/11/30 (内置函数)

技术分享

  

---------------------------------------------------------分割线----------------------------------

                                 随机验证码

 1 生成一个随机的验证码,65-90
 2 #数字转化为字母:chr(数字)
 3 import random
 4 
 5 temp = ""
 6 for i in range(4):
 7     num = random.randrange(0, 4)
 8     if num == 3 or num == 1:
 9         rad2 = random.randrange(0, 10)
10         temp = temp + str(rad2)
11     else:
12         rad1 = random.randrange(65, 91)
13         c1 = chr(rad1)
14         temp = temp + c1
15 print(temp)

 

 

  1 # def obj_len(arg):
  2 #     if isinstance(arg,str) or isinstance(arg,list) or isinstance(arg,tuple):
  3 #         if len(arg) > 5:
  4 #             return True
  5 #         else:
  6 #             return False
  7 #
  8 #     return None
  9 # temp = 123
 10 # ret = obj_len(temp)
 11 # print(ret)
 12 #
 13 
 14 #
 15 # def has_space(args):
 16 #     ret = True
 17 #     for c in args:
 18 #         if c.isspace():
 19 #             ret = False
 20 #             break
 21 #         return ret
 22 #
 23 #
 24 # result = has_space("111154533 __)(asd)")
 25 # print(result)
 26 
 27 #
 28 # def func(args):
 29 #     args.append(123)
 30 # li = [11,22]
 31 # func(li)
 32 # print(li)
 33 #
 34 
 35 
 36 
 37 #绝对值
 38 # i = abs(-123)
 39 # print(i)
 40 
 41 #all,循环参数如果灭个元素都为真,那么all的返回值为真
 42 # r = all([True,True,False])
 43 # print(r)
 44 
 45 #
 46 #假,0,NOne,"",[],(),{},  ==>>  0,None,空值
 47 
 48 
 49 #any 只有一个有真的,则为真
 50 # i = any([None,"",[],{},1])   "1"为真
 51 # print(i)
 52 
 53 #ascii,对象的类中找_repr_,获取其返回值
 54 # class Foo:
 55 #     def _repr_(self):
 56 #         return "hello"
 57 #
 58 # obj = Foo()
 59 # r = (obj)
 60 # print(r)
 61 
 62 #bin() #二进制
 63 # r = bin(11)
 64 # print(r)
 65 #
 66 # #oct() #八进制
 67 # r = oct(8)
 68 # print(r)
 69 #
 70 # #int() #十进制
 71 # r = int(10)
 72 # print(r)
 73 
 74 
 75 #hex() #十六进制
 76 # r = hex(14)
 77 # print(r)
 78 
 79 
 80 #chr()
 81 #ord()                            #啊思科码
 82 #一个字节,8位,2**8,256:ABC—(_ ascill)
 83 # c = chr(66)
 84 # print(c)
 85 #结果“B”
 86 
 87 # i = ord("T")
 88 # print(i)
 89 #结果“84”
 90 
 91 
 92 
 93 
 94 #filter(函数,可以迭代的对象)
 95 # def f1(x):
 96 #     if x > 22:   #如果X大于22
 97 #         return True
 98 #     else:
 99 #         return False
100 #
101 # ret = filter(f1, [11,22,33,44])
102 #
103 # for i in ret:
104 #     print(i)
105 
106 #lambda 表达式         ##同上
107 # ret = filter(lambda x: x>22, [11,22,33,44])
108 # for i in ret:
109 #     print(i)
110 
111 
112 #max  取最大值    [11,22,33,44]
113 #min  取最小值
114 
115 #pow  = (2,100)  取2的100次方

-------------------------------------------分割线-------------------------------

                                                    其他   

 1 #动态参数一
 2 # def f1(*a):   #加一个星号
 3 #    
 4 #万能参数
 5 # def f1(*a,**aa):        #在后面加多个星号
 6 #     print(a,type(a))
 7 #     print(aa,type(aa))
 8 # f1(11,22,33, k1=123,k2=456)
 9 
10 
11 
12 
13 
14 
15 #全局变量
16 # PERSON = "alex"
17 
18 # def func1():
19 #     #局部变量
20 #     a = 123
21 #     global PERSON    #global关键字,  全局变量大写,局部变量小写
22 #     PERSON = "eric"
23 #     print(a)
24 #
25 # def func2():
26 #     a= 456
27 #     print(PERSON)
28 #     print(a)
29 #
30 # func1()
31 # func2() print(a,type(a))
32 #
33 # f1(123,343243,)
34 
35 
36 #动态参数二
37 # def f1(**a): #加两个星号
38 #     print(a,type(a))
39 # f1(k1=123,k2=456)

 

2016/11/30 (内置函数)