String processing in python

1  # !/usr/bin/env python 
2  # -*- coding:utf-8 -*- 
3  # ######################### ## 
4  # File Name: strformat.py 
5  # Author: frank 
6  # Email: [email protected] 
7  # Created Time: 2018-04-28 12:23:00 
8  # ######### ################### 
9  
10  #Format configuration method inside the slot 11 # {<parameter number>:<format control flag>} 12 13 # : <filling> <alignment> <width> <,> <. precision> <type> 14 #
 
 
 
 Leading symbol used for padding < left-aligned slot set number of floating point decimal precision integer type 
15  #single            character> right-aligned output width thousand separator or string maximum output length b,c,d,o,x ,X 
16  #                      ^ Center-aligned float type 
17  #                                                                                     e,E,f,% 
18  
19 a= " {}: The CPU usage of the computer {} is {}% " .format( " 2018-10-10 " , " C " , 10 )
 20  print (a)
 21  
22  #String processing function 
23 
24  # str.lower() 
25  print ( " AbCdEfGh " .lower())
 26  # str.upper() 
27  print ( " AbCdEfGh " .upper())
 28  
29  # str.split(sep=None) returns a list , composed of the parts of str separated by sep 
30  print ( " A,B,C " .split( " , " ))
 31  
32  # str.count(sub) Returns the number of times the substring sub appears in str 
33  print ( " an apple a day " .count( " a" ))
 34  
35  # str.replace(old, new) returns a copy of the string str, all old substrings are replaced with new 
36  print ( " python " .replace( " n " , " n123.io " ))
 37  
38  # str.center(width, [fillchar]) The string str is centered according to the width width, filechar is optional. 
39  print ( " python " .center(20, " * " ))
 40  
41  # str.strip(chars) from str strip out the characters listed in the chars to its left and right 
42  print ( " = python=" .strip( " =np " ))
 43  
44  # str.join(ite) adds a str 45 after each element of the iter variable except the last element 
print ( " , " .join( " ABCDE " )) 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325021734&siteId=291194637