-
The string is immutable, and the list is mutable.
That is to say, once the meaning of the string is determined, it cannot be changed, but the list can.
abc"d = a','b','c']'e'And.
new_s = s + e'
Moreover, immutable means that it can be used as a dictionary key, while mutable is not messy.
Also, the approach to both things is different.
-
list_tmp=f = open('file_','r'for i in :list list tmp It's okay to have a shift faction to argue the mu?
-
If the file is not very large:
def findstrinfile(filename, lookup):
return lookup in open(filename,'rt').read()
Dealing with large files:
def findstrinlargefile(filename, lookup):
with open(filename, 'rt') as handle:
for ln in handle:
if lookup in ln:
return true
else:return false
-
You can use '' to split this string to get a list.
For example, if your string input is stored in the variable test string, then test'') is a list of 3 elements, each of which is a string (without line breaks).
-
>>>string = a_b_c_001a_b_c_002
a_b_c_003'''
>['a_b_c_001', a_b_c_002', a_b_c_003']
String operation, the splitlines function splits the string into rows and returns a list.
-
Separated by split. Or regular ...
a=""a_b_c_001
a_b_c_002
a_b_c_003
import re
p="(n]+)n")
result=;
print result
As a result, it was. [('a', b', c', 001'),a', b', c', 002'),a', b', c', 003')]
-
print sum(map(ord,list(where str1 is the input string.
Take ABC as an example:
Turn all letters into lowercase ABC.
list( turns the string into ['a', 'b', 'c']ord turns letters into ASCII numbers.
map(ord,list(Turns all letters in the list into numbers [97,98,99].)
sum.
After summing, since the ascii of a is 97, each letter has to be subtracted by 96.
Add a field in Table 1 as a foreign key and Billno in Table 2 >>>More
Do it by your train of thought.
Method 1. string strnumber="200m"; >>>More
Incorporating moral education into a day's activities is the most effective way to do it in everyday lifeEarly childhood teachersIt is necessary to be good at infiltrating the cultivation of children's good living habits and behavioral habits into preschool education. >>>More
It's very simple, select all the text toolbar** Convert text to** OK, then it will show the Chinese and English separately arrangement**, and then select all the text, click the toolbar** Convert**Convert to text OK, then ** is gone. All that's left is a neat two-line line of text. This method is simple, but the disadvantage is that it is not easy to master, and there is a certain skill in adjusting the width of the column, which is not clear here. >>>More
Horizontal top or top top of the page?
Hitting directly is horizontally topped. >>>More