Explain the variables in python in detail

  • 2021-12-12 09:22:49
  • OfStack

Classification of directory variables: naming rules for assignment variables: summary Classification of variables: naming rules of assignment variables: summary

Variable

1 Quantity defined by a programmer or user and subject to change in the program
The # variable is the starting point for all programs

Classification of variables:


 Immutable form : Unable to check a certain in a variable 1 Single order 1 Elements are modified, added, and deleted 
	 String  - str - string -  "Variable" 
	 Integer  - int - integer - 100
	 Floating point  - float - float - 3.111 1.0
	 Tuple  - tuple - tuple - (1,2,"a"," Good ")
  Variable type : You can check a certain in a variable 1 Single order 1 Or multiple elements can be modified, added or deleted 
	 Dictionary  - dict - dictionary - {"name":" Zhang 3","age":"33"}	
	 List  - list - list - [1,2," Zhang 3","a"]

Assignment

Assign from right to left


name = " Zhang 3"
name_list = [" Zhang 3","a"]
  Variable name    -Mapping-    Memory address    -    Memory storage 

name--2131231 [Zhang 3]

Naming rules for variables:


 Mandatory rule 
	1 Variable cannot begin with a number 
	2 Special characters cannot appear in variables (   Division _  Outside) 
	3 Variable name cannot have spaces 
	4 Variable names are case sensitive A And a Are two variables 
 The rule of common name of agreement 
	1 The Great Hump   ( ClassName1 Used as class name) 
	2 Little Hump   ( defName1 Used as method name) 
	3 , underline division   ( t_name1 Used as variable name) 
	4 No, no 0 (Zero) and o ( O ) as the beginning or end 

import string
import random
name = 'gaobo'
sex = 'nv'
nia = 'nan'
high = 3
 print(" Name %s , gender %s, Age %s Height %.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(" My extraction code: ", "".join(addlis))
 
qu_li = "".join(random.sample((string.ascii_lowercase + string.digits), 10))
 print(" My extraction code: ", 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(" My extraction code is ", a.join(my_code) )
#
# a = ''.join(random.sample((string.digits + string.ascii_lowercase),8))
# print(a)
#
#
'''
 

Summarize

This article is here, I hope to give you help, but also hope that you can pay more attention to this site more content!

Variable

1 Quantity defined by a programmer or user and subject to change in the program
The # variable is the starting point for all programs

Classification of variables:


 Immutable form : Unable to check a certain in a variable 1 Single order 1 Elements are modified, added, and deleted 
	 String  - str - string -  "Variable" 
	 Integer  - int - integer - 100
	 Floating point  - float - float - 3.111 1.0
	 Tuple  - tuple - tuple - (1,2,"a"," Good ")
  Variable type : You can check a certain in a variable 1 Single order 1 Or multiple elements can be modified, added or deleted 
	 Dictionary  - dict - dictionary - {"name":" Zhang 3","age":"33"}	
	 List  - list - list - [1,2," Zhang 3","a"]

Assignment

Assign from right to left


name = " Zhang 3"
name_list = [" Zhang 3","a"]
  Variable name    -Mapping-    Memory address    -    Memory storage 

name--2131231 [Zhang 3]

Naming rules for variables:


 Mandatory rule 
	1 Variable cannot begin with a number 
	2 Special characters cannot appear in variables (   Division _  Outside) 
	3 Variable name cannot have spaces 
	4 Variable names are case sensitive A And a Are two variables 
 The rule of common name of agreement 
	1 The Great Hump   ( ClassName1 Used as class name) 
	2 Little Hump   ( defName1 Used as method name) 
	3 , underline division   ( t_name1 Used as variable name) 
	4 No, no 0 (Zero) and o ( O ) as the beginning or end 

import string
import random
name = 'gaobo'
sex = 'nv'
nia = 'nan'
high = 3
 print(" Name %s , gender %s, Age %s Height %.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(" My extraction code: ", "".join(addlis))
 
qu_li = "".join(random.sample((string.ascii_lowercase + string.digits), 10))
 print(" My extraction code: ", 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(" My extraction code is ", a.join(my_code) )
#
# a = ''.join(random.sample((string.digits + string.ascii_lowercase),8))
# print(a)
#
#
'''
 

Summarize

This article is here, I hope to give you help, but also hope that you can pay more attention to this site more content!


Related articles: