Python _ string operations, python _ string operationsI. String methods and operations
* Note: if the first character is l, it indicates the operation from the left. If the first character is r, it indicates the operation from the right.1. _ contains _ () determines whether
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
1. DictionariesDict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}Dictionary converted to string, return: Print type (str (dict)), str (DICT)Dictionaries can be converted to tuples, returning: (' age ', ' name ', ' class ')Print tuple (dict)#字典能够转为元组, return: (7, ' Zara ', ' first ')Print tuple (dict.values ())Dictionary to list. return: [' age ', ' name ', ' class ']Print
List generation: Creating a listNormal Create List format:1. Defining a list variable2.for.. In.. :StatementList-generated lists format:[Statement for ...]As you can see, the list generation is just a matter of referring the for statement to the for peer.First, the normal creation
is only a temporary variable and must be assigned a value to save it.
Copy the Code as follows:
# Example 2: String replacement
Str = 'akakakak'
Str = str. replace ('k', '8') # replace all k in the string with 8
Print str
> 'A8a8a8 '# output result
Python searches for strings using variables. find ("content to be searched" [, start position, end position]), sta
Introduction to reduce and map in Python
map(func,seq1[,seq2...]) : func function to each element of a given sequence, using a list to provide the return value, or, if Func is an identity function for None,func, returns a list of n tuples containing the set of elements in each sequence.
reduce(func,seq[,init]) : Func is a two-dollar function, the elements that
\ Site-packages \ py2exe \ Samples Directory.
Iii. Usage of py2exe
If you have a file named myscript. you want to convert the Python script of Py to an executable program running on Windows and run it on a Windows system without Python installed, first, you should write a setup script for the release program, such as mysetup. PY, insert the statement import
() # returns the division result and remainder
Max ([,]) # calculate the maximum value
Min ([,-]) # calculate the minimum value
Sum ([2,-1, 9, 12]) # sum
Type conversion
Int ("5") # Convert to integer
Float (2) # Convert to float
Long ("23") # Convert to a long integer
Str (2.3) # Convert to
, 6, 7, 8, 9, 10]
>>> Tist [0: 10: 1][1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>>> Tist [][1, 3, 5, 7, 9]
If we want to extract one of the three elements from the beginning to the end, we only need to do this.
>>> Tist [: 3][1, 4, 7, 10]
(4) append element list. append
>>> Lis = [1, 2, 4, 5, 6]>>> Lis. append (7)>>> Lis[1, 2, 3, 4, 5, 6, 7]
(5) delete the list element del list
Python_way, day2 string, list, dictionary, time module 1, Input:2.0 3.0 Differences2.0 inIf you want the user to interact with the input string:Name=raw_input ()IfName=input () is to pass what is the corresponding what, want to enter the string need to add "" "quotation marks, if not added to think that the incoming is a variable.A= "hahaha"User=input ("Shuru:")P
Reprint Address: http://liyangliang.me/posts/2012/10/python-timestamp-to-timestr/When writing python, often encounter time format problems, each time is on Google search and then find someone else's blog or website for reference. Now to summarize their own simple, convenient later query.The first is the conversion between the recently used timestamp (timestamp) and the time
stringTogether, unless you first convert the list to a string.>>> STR ([up]) + ' 34 '' [1, 2]34 '>>> [1,2]+list (' 34 ')[1, 2, ' 3 ', ' 4 ']2, index, Shard, matrixThe result of indexing a list is the object at the offset you specify (regardless of type), and a new
0. Description9 months did not write Python, this 9 months in the Huawei ICT knowledge of the sea, the previous time just passed the Hcie certification, think of still like Python and Linux more, so back, there will be more and more python dry share to everyone, For example, later will be going to write a complete Linux host monitoring project of the tutorial to
This time brings you to python how to convert matrices to lists, Python to convert the matrix to list of considerations, the following is the actual case, take a look.
This article focuses on some of the functions in Python's numpy library and makes backups to find them.
(1
='Discover Python" ^SyntaxError: EOL while scanning single-quoted string>>> sr="Discover Python: \... It's Wonderful!">>> print srDiscover Python: It's Wonderful!
From List 1, we can see that in addition to the strings enclosed by proper quotation marks,
Please convert this php code into python code. thank you! {Code...} is simply to sort the array in reverse order and convert it to json format. Please convert this php code into python code. thank you!
// Inverted sorting function my_sort ($ a, $ B) {if ($ a = $ B) return 0
, 2, 3]>>> X[0][1]' B '>>> X[1][1]2‘‘‘#9, Python list functions‘‘‘ordinal function1 len (list)Number of list elements2 Max (list)Returns the maximum value of a list element3 min (list)R
In the Python programming language, developed programs can be converted into EXE files for specific operations. Here, we will give you a detailed introduction to the operations on converting a Python program into an EXE file, so that you can get some help.
Analysis of basic Python String applications
Summary of
In Python programming, the most common types of collections we use are: list,tuple,set,dict; let's talk about these types of collections in a few simple ways;List lists: Equivalent to an array, but the length of the list is automatically changed and the elements are free, without having to be the same type for each ele
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.