Python Activation and String Operations
pycharm activation (general method for JetBrains IDEA series products)
1. Open the activation window
2. Select Activate new license with License server (activate using license server)
3. Enter https://jetlicense.nss.im/ in the License sever address field
4. Click Activate to authenticate
5. done!
pycharm activation
EB101IWSWD-eyJsaWNlbnNlSWQiOiJFQjEwMUlXU1dEIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IkZvciBlZHVjYXRpb25hbCB1c2Ugb25seSIsImNoZWNrQ29uY3VycmVudFVzZSI6ZmFsc2UsInByb2R1Y3RzIjpbeyJjb2RlIjoiSUkiLCJwYWlkVXBUbyI6IjIwMTgtMTAtMTQifSx7ImNvZGUiOiJSUzAiLCJwYWlkVXBUbyI6IjIwMTgtMTAtMTQifSx7ImNvZGUiOiJXUyIsInBhaWRVcFRvIjoiMjAxOC0xMC0xNCJ9LHsiY29kZSI6IlJEIiwicGFpZFVwVG8iOiIyMDE4LTEwLTE0In0seyJjb2RlIjoiUkMiLCJwYWlkVXBUbyI6IjIwMTgtMTAtMTQifSx7ImNvZGUiOiJEQyIsInBhaWRVcFRvIjoiMjAxOC0xMC0xNCJ9LHsiY29kZSI6IkRCIiwicGFpZFVwVG8iOiIyMDE4LTEwLTE0In0seyJjb2RlIjoiUk0iLCJwYWlkVXBUbyI6IjIwMTgtMTAtMTQifSx7ImNvZGUiOiJETSIsInBhaWRVcFRvIjoiMjAxOC0xMC0xNCJ9LHsiY29kZSI6IkFDIiwicGFpZFVwVG8iOiIyMDE4LTEwLTE0In0seyJjb2RlIjoiRFBOIiwicGFpZFVwVG8iOiIyMDE4LTEwLTE0In0seyJjb2RlIjoiUFMiLCJwYWlkVXBUbyI6IjIwMTgtMTAtMTQifSx7ImNvZGUiOiJDTCIsInBhaWRVcFRvIjoiMjAxOC0xMC0xNCJ9LHsiY29kZSI6IlBDIiwicGFpZFVwVG8iOiIyMDE4LTE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GZMIGWMAkGA1UdEwQCMAAwHQYDVR0OBBYEFGEpG9oZGcfLMGNBkY7SgHiMGgTcMEgGA1UdIwRBMD+AFKOetkhnQhI2Qb1t4Lm0oFKLl/GzoRykGjAYMRYwFAYDVQQDDA1KZXRQcm9maWxlIENBggkA0myxg7KDeeEwEwYDVR0lBAwwCgYIKwYBBQUHAwEwCwYDVR0PBAQDAgWgMA0GCSqGSIb3DQEBCwUAA4ICAQC9WZuYgQedSuOc5TOUSrRigMw4/+wuC5EtZBfvdl4HT/8vzMW/oUlIP4YCvA0XKyBaCJ2iX+ZCDKoPfiYXiaSiH+HxAPV6J79vvouxKrWg2XV6ShFtPLP+0gPdGq3x9R3+kJbmAm8w+FOdlWqAfJrLvpzMGNeDU14YGXiZ9bVzmIQbwrBA+c/F4tlK/DV07dsNExihqFoibnqDiVNTGombaU2dDup2gwKdL81ua8EIcGNExHe82kjF4zwfadHk3bQVvbfdAwxcDy4xBjs3L4raPLU3yenSzr/OEur1+jfOxnQSmEcMXKXgrAQ9U55gwjcOFKrgOxEdek/Sk1VfOjvS+nuM4eyEruFMfaZHzoQiuw4IqgGc45ohFH0UUyjYcuFxxDSU9lMCv8qdHKm+wnPRb0l9l5vXsCBDuhAGYD6ss+Ga+aDY6f/qXZuUCEUOH3QUNbbCUlviSz6+GiRnt1kA9N2Qachl+2yBfaqUqr8h7Z2gsx5LcIf5kYNsqJ0GavXTVyWh7PYiKX4bs354ZQLUwwa/cG++2+wNWP+HtBhVxMRNTdVhSm38AknZlD+PTAsWGu9GyLmhti2EnVwGybSD2Dxmhxk3IPCkhKAK+pl0eWYGZWG3tJ9mZ7SowcXLWDFAk0lRJnKGFMTggrWjV8GYpw5bq23VmIqqDLgkNzuoog==
python activation code
- in and not in differences
#/usr/bin/env python
#-*-coding:utf-8-*-
name = "郑建文"
# if "建文" in name:
# print('ok')
# else:
# print('error')
if "文1" not in name:
print('1')
else:
print('2')
- Boolean values:
Either True or False
- Basic data types
Numbers int all functions are in int
---------int ####Convert string to number
a = "123"
print(type(a),a)
b = int(a)
print(type(b),b)
num = "0011"
v = int(num,base=16) #####base indicates the base system
print(v)
---------bit_lenght ######The minimum number of bits required to represent the current number
age = 10
r = age.bit_length()
print(r)
String str
test = "alex"
##########capitalize first letter uppercase
v = test.capitalize()
print(v)
test = "aLex"
###############center
#Set width and center content
#20 represents total length
#* blank fill, one character, optional
v = test.center(20,"*")
print (v)
# test = "aLexalex"
###########count find substring occurrences, can define start and end positions
# v = test.count('ex')
# print(v)
test = "aLexalex"
v = test.count('ex',5,6)
print(v)
test = "alex"
###endswith ends with ###startswith starts with#
v = test.endswith('ex')
v = test.startswith('a')
print(v)
test = "alexalex"
##Find the first occurrence from the beginning and get its position
#> or >=
v = test.find('ex',5,8)
print (v)
test = 'i am {name},age{a}'
#format format, replace placeholders in a string with specified values
print(test)
v = test.format(name='alex',a=19)
####b = test.format_map("name":'alex',"a":19)
print (v)
################################
test = 'i am {0},age{1}'
print(test)
v = test.format('alex',19)
print (v)
test = "uasf890"
###Check if the string contains only letters and numbers
v = test.isalnum()
print(v)
######expandtabs split 20 can be used to create a table
test = "username\temail\tpassword\nzhao\tzhao@q.com\t123\nzhao\tzhao@q.com\t123\nzhao\tzhao@q.com\t123\n"
v = test.expandtabs(20)
print(v)
#######Check if it is alphabetic
test = "abcd"
v= test.isalpha()
print (v)
#######Check if it is numeric
test = "11"
v1 = test.isdigit()
print (v1)
######swapcase case conversion
test = "abcde"
v = test.swapcase()
print (v)
#####All lowercase to uppercase
test ="AleX"
v2 = test.upper()
print(v2 )
#####Check if all are uppercase
test ="AX"
v1 = test.isupper()
print(v1 )
##############All letters to lowercase
test ="AleX"
v1 = test.lower()
print(v1)
######islower check if the string consists of lowercase letters
test = "abcde"
v = test.islower()
print(v)
###isidentifer check if the string consists of letters, numbers, and underscores as an identifier def class
a = "def"
v = a.isidentifer()
print (v)
####isprintable check if it contains printable characters####是否存在不可见的字符
####\t tab character
####\n newline character
test = "oiusdfkj"
v = test.isprintable()
print(v)
#####is title check if the first letter is uppercase
test ="A1 A2 A3"
v = test.istitle()
print(v)
###### title convert all first letters to uppercase which is the title
test = "A1 a2 A3 a4"
v1 = test.title()
print (v1)
####Join each element of the string with a specified separator
test = "你是风儿我是沙"
v = '_'.join(test)
print (v)
###########Padding on the right###20 is the length, * represents filling with *
test="alex"
v = test.ljust(20,"*")
print (v)
###########Padding on the left###20 is the length, * represents filling with *
v1 = test.rjust(20,"*")
print(v1)
###################Replace with 000, a total of 20 bytes length
v2 =test.zfill(20)
print(v2)
##############Default removes spaces, removes \n line breaks remove \t, can also remove specified characters
#test = " alex "
# test = "\talex"
# v = test.lstrip()#####Remove left spaces
#v = test.rstrip() #####Remove right spaces
# v = test.strip() #####Remove both sides spaces
test = "xalex"
v = test.lstrip('xa') #### lex ####
#v = test.rstrip('x') #### xale ###
#v = test.strip('x') ##### ale ###
print (v)
#############
test = "testtasdsddfg"
#v = test.partition('t') #####Split into three parts from the left
#v = test.rpartition('s') #######Split into three parts from the left
#v = test.split('s',2) ######Split based on what, the parameter can choose the number of splits
test = "testt\nasdsd\ndfg"
v = test.splitlines(True) ###########Split by newline, true retains, false does not retain
# test.rsplit()
print(v)
##############
test = "backend 1.1.1.1"
#v= test.startswith('ba') ###############Starts with what
v =test.endswith('1') ###############Ends with what
print(v)
###################String modification
test = "alexalexalex"
v = test.replace("alex","made",2) ##### The first is the content parameter, the second is the replacement parameter, the number represents how many to replace, default replaces all
print (v)
######### In Python 2.7, memory is immediately created,###In Python 3, it will not immediately create in memory##Only creates when called
############This is an optimization mechanism
v = range(0,100,5) ####Help create continuous numbers, can also set step size to decide non-continuous
for i in v:
print(i)
####Seven basic magic of strings########
###join concatenate ### split delimiter #### find find ### strip remove spaces## upper replace to uppercase ## lower replace to lowercase## replace replace characters
####range create numbers
####Four gray magic of strings#############
for loop ##### len calculate characters ### slice### index###
#####Deep gray magic of strings##########
####Strings cannot be modified once created
####Once modified or concatenated, a new string is generated
Exercise:
#################Enter any character, print out the character and corresponding index
test = input(">>>")
for i in range(0,len(test)):
print(i,test[i])
Strings
1 Execute Python scripts in two ways
2 Directly call the Python script, use the Python interpreter to call the Python script
3
4 Briefly describe the relationship between bits and bytes
5 One byte is eight bits, computer calculations are in bytes, storage is in bits
6
7 Briefly describe the relationship between ASCII, Unicode, UTF-8, GBK
8 The earliest was ASCII encoding, followed by Unicode encoding, due to different national standards, then came the compressed encoding of Unicode, UTF-8. ASCII uses 8 bits, Unicode uses 16 bits. Using ASCII to represent characters in Unicode would cause memory waste, so UTF-8 encoding was proposed, which uses as many bits as needed.
9
10 4, please write down the number of bits occupied by "Li Jie" respectively using UTF-8 and GBK encoding
11 UTF-8 Chinese characters represent 3 bytes, occupying 6 bytes
12 GBK represents 2 bytes, occupying 4 bytes
13 5, What are the single-line comments and multi-line comments in Python?
14 Single-line uses # Multi-line uses """ """"""
15 6, What are the notes when declaring variables?
16 Numbers, underscores, letters, numbers cannot start, must not repeat keyword names. Try not to use Python built-in function names, which may cause errors.
17 If there is a variable n1 = 5, please use the method provided by int to get the minimum number of binary bits that the variable can be represented with?
18 n = 5
19 print n.bit_length()
20 3 bits
21
22 8, What are the Boolean values?
23 True False
24 9, Read the code and write the execution result
25
26 a = "alex"
27 b=a .capitali()
28 print(a) print(b)
29
30 Write the output result:
31
32 alex Alex
33
34
35
36 10, Write code, with the following variable, implement each function as required
37 name = " aleX"
38
39 Remove the spaces on both sides of the value corresponding to name and print the result print name.strip()
40 b. Determine whether the value corresponding to name starts with "al" and output the result print(name.startswith('al'))
41
42 c. Determine whether the value corresponding to name ends with "X" and output the result print(name.endswith('X'))
43
44
45 d. Replace "l" in the value corresponding to name with "p", and output the result e. Split the value corresponding to name by "l" and output the result.
46
47 aname=name.replace("l","p")
48
49 f. What type is the value obtained in the previous question e? (optional)
50 print(type(name.split('e')))
51
52
53 g. Convert the value corresponding to name to uppercase and output the result
54 print(name.upper())
55
56 h. Convert the value corresponding to name to lowercase and output the result
57 print(name.lower())
58
59 i. Please output the second character of the value corresponding to name?
60 print(name[1])
61
62 j. Please output the first three characters of the value corresponding to name?
63
64 print(name[0:3])
65
66 k. Please output the last two characters of the value corresponding to name?
67 print(name[-2:])
68
69 l. Please output the index position where "e" is located in the value corresponding to name?
70 print(name.find("e"))
71
72 m. Get a substring, excluding the last character. For example: oldboy, get oldbo; root, get roo
73 print(name[:len(name) -1])
74
75 21. Is a string an iterable object? If yes, use for loop to iterate through each element?
76
77 name ="aleX"
78 for i in name:
79 print(i)
80
81
82 22. Please use code to implement:
83
84 a. Use underscores to join every element of the list into a string, li = "alexericrain"
85 a = "alexericrain"
86 v = ("_".join(a))
87 print(v)
88
89 23. What is the difference between range in Python 2 and Python 3?
90 Python 2 directly creates in memory, while Python 3 creates in memory when called, which is an optimization mechanism, saving memory
91
92 24. Implement a calculator for integer addition:
93
94 For example:
95
96 content = input('Please enter content:') # For example: 5+9 or 5+ 9 or 5 + 9
97 value = input("shuru")
98 v1,v2 = value.split('
99 v1 = int(v1)
100 v2 = int(v2)
101 print(v1+v2)
102
103
104 25. Calculate how many decimal digits and letters are in the user's input content? For example:
105
106 content = input('Please enter content:') # For example: asduiaf878123jkjsfd-‐213928 26. Briefly describe the relationship between int and 9 and str and "xxoo" and other strings?
107
108
109
110 27. Create a fun template program, wait for the user to input name, location, and hobbies, and display according to the user's name and hobbies
111
112 For example: Dear and beloved xxx, the favorite place to do xxx
113
114 28. Create a random verification code, case-insensitive. Process:
115
116 -‐ User runs the program -‐ Display the verification code to the user -‐ User inputs the value
117
118 If the user's input value matches the displayed value, display the correct message; otherwise, continue generating random verification codes and wait for the user to input. Code example for generating random verification codes:
119
120
121
122 29. Develop a sensitive word filtering program, prompt the user to input content, if the user's input content contains special characters: such as "Cang Lao Shi" "Tokyo Hot", then replace the content with ***
123
124
125
126 30. Create a table to prompt the user to input: username, password, email (the requirement is that the user's input length does not exceed 20 characters, if it exceeds, only the first 20 characters are valid)
127
128 If the user inputs q or Q, it means no longer continue to input, and the user's input content is displayed in a table format