[Switch] Python string operation implementation code (capture/replace/search/split), python string
Address: http://www.jb51.net/article/38102.htm
Ps: I haven't updated the python code for a long time. I used a string this time. Le
List, String, Dictionary common operations in python, python string
The list operation is as follows:
A = ["haha", "xixi", "baba"]Increment: a. append [gg]A. insert [1, gg] To the place marked as 1, add ggDelete: a. remove (haha) deletes the first matched haha from left to right in the list.Del a. [0] Delete the value
Python string formatting, python string
It is used for String concatenation and has better performance.
Two methods are available for string formatting: percent sign and format.
The percent sign method is relatively old, while the
How to flip a string or list in Python, and how to flip a string in python
1. reversed
class reversed(object) | reversed(sequence) -> reverse iterator over values of the sequence | | Return a reverse iterator | | Methods defined here: | | __getattribute__(...) | x.__getattribute__('name')
The processed
follows. Path: The Path to be determined. The following example checks whether E: \ book \ Temp is a file.
>>>importos
>>>os.path.isfile('E:\\book\\temp')
Determine whether it is a file
False
E: \ book \ Temp is not used to list all files in the directory.
Keywords:
dirimportstring,os,sys
dir='/var'
print'-----------nosubdir'
files=os.listdir(dir)
forfinfiles:
printdir+os.sep+f
print'-----------alldir'
forroot,dirs,filesinos.walk(dir):
fornameinfile
Common string-related function summary in python, python string
This example summarizes the commonly used string-related functions in python. Share it with you for your reference. The specific analysis is as follows:
The followi
Basic Python-string, basic python stringBasic string syntax
Print () Output
In Python 3, strings are Unicode encoded. That is to say, Python strings support multiple languages.
Chr () encoding into characters ord()Integer represe
Python (1) string usage and python string usageI. program output: print is in Python2.X. The usage of print is: print "hello word! "In Python3.X, print appears as a function. Usage: print (" hello word !")Output number: print (1) Output string: print ("1") output variable: p
Python provides simple string matching details and python string details.
Python for simple string matching
Since fields in specific formats need to be extracted from semi-structured text data, and data mining and analysis can b
Python string connection method analysis, python string connection
This article analyzes the python string connection method. We will share this with you for your reference. The details are as follows:
There are several methods
The role of adding r to the string in python, and the role of the python string
This example describes how to add r before a string in python. Share it with you for your reference. The specific analysis is as follows:
Adding r b
Python string processing implements word inversion, python string
In Python string processing, there is a simple but classic question. The string is reversed by word and the original sp
Several methods of string in python, python string
String formatting
>>> '%s plus %s equals %s' % (1,1,2)'1 plus 1 equals 2'
Field width and precision
* The field width is the minimum number of characters retained by the converted value, and the precision (for digits) is the
Python automated development (5): Introduction to Python, Python encoding, receiving and execution parameters, analysis of string principles, and python Encoding
Python automated development (5):
Python original string, python string
1 str1 = 'let's go '2 File "
Because str1 contains "'", the compiler cannot escape and report an error. The correct code is as follows:
Str1 = 'let \'s go 'str1 "let's go"
Use \ as the escape character to escape the characters in the stri
Format the python string and format the python string.
Most of the time, when printing input content, we want a simple format instead of splicing.
General Practice:
1 name = input("name:").strip()2 age = input("age:").strip()3 job = input("job:").strip()4 print("Name:" + name + " Age:" + age + " Job:" + job)
Result:
Na
Common python string processing and python string processing
S. find (substring, [start [end]) # searches for substrings in the specified range and returns the index value. Otherwise,-1 is returned.
For example
>>> B = 'abc'>>> B. find ('D ')3>>> B. find ('D', 2, 4)3>>> B. find ('D', 3,4)3
>>> B. find ('D', 2, 3)-1
similar to the C language, the first element is labeled 0, the second element is labeled 1, and so on. Python also has the penultimate element labeled-1, the second-to-last element is labeled-2, and so on.
generates an error if the subscript is out of bounds
specifically, elements inside strings are read-only, and statements like ' Hello ' [0]=0] produce errors
>>G T hello [1 e >>> a=[1,2,3,4,4" >>
: EXEC (' raw_input ("Arithmetic expression:") does not error, because ECEC can also be used for expressions, but nothing is achieved (neither return value nor do anything).Like exec, Eval can also use namespaces. Because although the expression generally does not reassign the variable, the expression can be used to assign a value to the global variable by calling the function. For example, when the following code is executed, the value of the global variable x is re-assigned to a value of 2:x=1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.