String functions

Function for each data type, where the main strings in stresses
int
    string is converted to a digital
    A = '123'
    Print (type (A), A)
    B = int (A)
    Print (type (B), B)


string STR

casefold and all modifications that can lower lowercase, casefold worse, many variations are unknown lowercase
V1 = test.casefold ()
Print (V1)
V2 = test.lower ()
Print (V2)

Center set the width , the contents of the center
Test = 'Alex'
V = test.center (20 is, '*')
Print (V)
-------------------
****** ** aLex ********

whether the inspection end in a certain letter endswith
Test = 'Alex'
V = test.endswith ( 'EX')
Print (V)
----------------------- ----
True


COUNT sequence number to find the string that appears in the
Test = 'aldffd'
V = test.count ( 'D')
Print (v)
----------------
2

-----------------------
Test = 'aldffd'
V = test.count ( 'D', l, 3)
Print (V)
--- --------
. 1




the format is a format, a string placeholder with the value specified
Test = 'I AM {name}, Age {a}'
V = test.format (name = 'Alex', A =. 19)
Print (V)
-----------------------
I AM Alex, Age. 19
--------- ----------------------
V2 = test.format_map ({ 'name': 'Alex', 'A':}. 19) Dictionary incoming


isalnum query characters string contains only letters and numbers


expandtabs punctuation
test = 'username \ temail \ tpassword \ nlaiying \ [email protected] \ t123 \ nlaiying \ [email protected] \ t123 \ nlaiying \ [email protected] \ t123 \ n '
V = Test.expandtabs(20)
print(v)
---------------------
username            email               password
123 [email protected] laiying
laiying [email protected] 123
laiying [email protected] 123



the isalpha check whether letters or characters

isdecimal, isdigit, isnumeric check whether the number, the extent of gradual strengthening powerful
character isprintable check if there are undisplayable
title to the first letter of each word capitalized
join symbols used within each character
test = 'you are the wind is what I'
t = ''
v = t.join (the Test)
Print (v)
---- -------------
you are the wind I was what


ljust placed on the left of the string, completion vacancy
rjust string at the right side, vacancy complement
the Test = 'alex'
v = the Test .rjust (20 is, '*')
Print (V)
----------------
********************************************************* Alex

the lstrip string removed spaces left
rstrip strips spaces string on the right
strip remove space around a string of
alternative character translate
partition according to whether a character segmentation
= Test 'ahinvla'
V = test.partition ( 'n-')
Print (V)
--------------
( 'AHI', 'n-', 'VLA')
rpartition only points three, intermediate position, whichever
split according to whether a character segmentation, and removes a character, may specify additional parameters back artificially split times (regex)





teacher's blog is
www.cnblogs.com/wupeiqi/articles/5433925.html







Guess you like

Origin www.cnblogs.com/xuxiaoxiao97/p/12516916.html