变量
一个由程序员或用户定义的量且在程序中可能发生改变的量
#变量是所有程序的起点
变量的分类:
1
2
3
4
5
6
7
8
|
不可变型:无法对变量内的某一个单一元素进行修改、增加、删除
字符串 - str - string - “变量”
整数 - int - integer - 100
浮点 - float - float - 3.111 1.0
元组 - tuple - tuple - ( 1 , 2 , "a" , "好" )
可变型:可以对变量内的某一个单一或多个元素进行修改、增加、删除
字典 - dict - dictionary - { "name" : "张三" , "age" : "33" }
列表 - list - list - [ 1 , 2 , "张三" , "a" ]
|
赋值
从右向左赋值
1
2
3
|
name = "张三"
name_list = [ "张三" , "a" ]
变量名字 —映射— 内存地址 — 内存存储
|
name —— 2131231 “张三”
变量的命名规则:
1
2
3
4
5
6
7
8
9
10
|
强制性规则
1、变量开头不能是数字
2、特殊字符不能出现在变量中( 除_ 外)
3、变量名称不能出现空格
4、变量名区分大小写A和a是两个变量
约定俗称的规则
1、大驼峰 (ClassName一般用做类名)
2、小驼峰 (defName一般用做方法名)
3、下划线分割 (t_name一般用做变量名)
4、不用0(零)和o(O)作为开头或结尾
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import string
import random
name = 'gaobo'
sex = 'nv'
nia = 'nan'
high = 3
print ( "姓名%s,性别%s,年龄%s,身高%.2f" % (name, sex, nia, high))
list2 = [ "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' ]
addlis = []
for i in range ( 8 ):
qu = list2[random.randint( 0 , len (list2) - 1 )]
print (qu)
addlis.append(qu)
print (addlis)
print ( "我的提取码:" , "".join(addlis))
qu_li = "".join(random.sample((string.ascii_lowercase + string.digits), 10 ))
print ( "我的提取码:" , qu_li)
'''
# name = "1"
# age = '2'
# sex = '3'
# word = '4'
# a = '5'
# print("%s"'%s''%s''%s' % (name, age, sex, word), "%s" %(a))
#
# rand = string.digits + string.ascii_letters
list1 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
add_list = []
for i in range(8):
qu_1 = list1[random.randint(0, len(list1)-1)]
add_list.append(qu_1)
print("".join(add_list))
add_l = "".join(random.sample((string.digits + string.ascii_lowercase), 8))
print(add_l)
# list = ["0","1","2","3","4","5","6","7","8","9",'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
# my_code = []
# for i in range(8):
# qu_code = list[random.randint(0, len(list)-1)]
# print(qu_code)
# my_code.append(qu_code)
# a = ""
# print("我的提取码为", a.join(my_code) )
#
# a = ''.join(random.sample((string.digits + string.ascii_lowercase),8))
# print(a)
#
#
'''
|
总结
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注服务器之家的更多内容!
变量
一个由程序员或用户定义的量且在程序中可能发生改变的量
#变量是所有程序的起点
变量的分类:
1
2
3
4
5
6
7
8
|
不可变型:无法对变量内的某一个单一元素进行修改、增加、删除
字符串 - str - string - “变量”
整数 - int - integer - 100
浮点 - float - float - 3.111 1.0
元组 - tuple - tuple - ( 1 , 2 , "a" , "好" )
可变型:可以对变量内的某一个单一或多个元素进行修改、增加、删除
字典 - dict - dictionary - { "name" : "张三" , "age" : "33" }
列表 - list - list - [ 1 , 2 , "张三" , "a" ]
|
赋值
从右向左赋值
1
2
3
|
name = "张三"
name_list = [ "张三" , "a" ]
变量名字 —映射— 内存地址 — 内存存储
|
name —— 2131231 “张三”
变量的命名规则:
1
2
3
4
5
6
7
8
9
10
|
强制性规则
1、变量开头不能是数字
2、特殊字符不能出现在变量中( 除_ 外)
3、变量名称不能出现空格
4、变量名区分大小写A和a是两个变量
约定俗称的规则
1、大驼峰 (ClassName一般用做类名)
2、小驼峰 (defName一般用做方法名)
3、下划线分割 (t_name一般用做变量名)
4、不用0(零)和o(O)作为开头或结尾
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import string
import random
name = 'gaobo'
sex = 'nv'
nia = 'nan'
high = 3
print ( "姓名%s,性别%s,年龄%s,身高%.2f" % (name, sex, nia, high))
list2 = [ "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' ]
addlis = []
for i in range ( 8 ):
qu = list2[random.randint( 0 , len (list2) - 1 )]
print (qu)
addlis.append(qu)
print (addlis)
print ( "我的提取码:" , "".join(addlis))
qu_li = "".join(random.sample((string.ascii_lowercase + string.digits), 10 ))
print ( "我的提取码:" , qu_li)
'''
# name = "1"
# age = '2'
# sex = '3'
# word = '4'
# a = '5'
# print("%s"'%s''%s''%s' % (name, age, sex, word), "%s" %(a))
#
# rand = string.digits + string.ascii_letters
list1 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
add_list = []
for i in range(8):
qu_1 = list1[random.randint(0, len(list1)-1)]
add_list.append(qu_1)
print("".join(add_list))
add_l = "".join(random.sample((string.digits + string.ascii_lowercase), 8))
print(add_l)
# list = ["0","1","2","3","4","5","6","7","8","9",'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
# my_code = []
# for i in range(8):
# qu_code = list[random.randint(0, len(list)-1)]
# print(qu_code)
# my_code.append(qu_code)
# a = ""
# print("我的提取码为", a.join(my_code) )
#
# a = ''.join(random.sample((string.digits + string.ascii_lowercase),8))
# print(a)
#
#
'''
|
总结
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注服务器之家的更多内容!
原文链接:https://blog.csdn.net/Tallbo/article/details/121220526