Python string method

Source: Internet
Author: User

Well, learning other languages has not been practiced all the time, hehe.

test.py

1 #-*-Coding:utf-8-*-
2
3 str = "I am worker"
4 Print str.capitalize ()
5 Print Str.center (20)
6 print Str.count (")
7 Print Str.count (", 0, 4)
8 str1 = "China"
9 Str1.decode (' Utf-8 '). Encode (' gb2312 ')
Ten print str1
One str2 = U ' China '
Str2.encode (' gb2312 ')
Print str2
Print Str.endswith (' er ')
Print Str.endswith (' er ', 0, 6)
STR3 = ' 1 3 5 '
Print STR3
Print Str3.expandtabs ()
Print Str3.expandtabs (1)
Print Str.find (' m ', 0, Len (str))
#print str.index (' h ', 0, Len (str)) #exception
Print ". Isalnum ()
print '? 1a '. Isalnum ()
print ' 1a '. Isalnum ()
print ' 1 '. Isalpha ()
#print ' isdecimal ', ' 1a '. Isdecimal () #no Implement
print ' isdigit ', ' 1a '. IsDigit ()
#print ' IsNumeric ', ' 1a '. IsNumeric () #no Implement
print ' islower ', ' 1a '. Islower ()
Print ". Isspace ()
print ' You are fool '. Istitle ()
print ' You are fool '. Istitle ()
print ' 1a '. Isupper ()
print ' and '. Join ([' 1 ', ' 2 ', ' 3 '])
print ' 123 '. Ljust #make no sense of
print ' ABC '. Lower ()
PNS print ' abc '. UPPER ()
print ' AbAB '. Lstrip ()
#print ' 123abc ' Maketrans (' 123 ', ' ABC ') #no implement
+ print ' 123 '. partition (' 2 ')
print ' 123 '. partition (' 1 ')
print ' 123 '. Partition (' 3 ')
print ' 123 '. Partition (' 4 ')
print ' 113 '. Replace (' 1 ', ' 2 ')
print ' 113 '. Replace (' 1 ', ' 2 ', 1)
print ' 11a '. RFind (' a ')
print ' 11a '. Rindex (' a ')
print ' 123 '. Rjust (8)
print ' 123 '. Rpartition (' 2 ')

print ' 123 '. Rstrip ()
print ' 12134 '. Split (' 1 ')
print ' 12134 '. Split (' 1 ', 1)
print ' 1\r2\r\n3\n '. Splitlines (True)
print ' 1\r2\r\n3\n '. Splitlines (False)
print ' 123 '. StartsWith (' 1 ')
+ print ' 123 '. Strip ()
print ' Ababab '. Swapcase ()
print ' abc def HGJ '. Title ()
1aabb?>< ' Translate (None, ' <> ')
print ' 123 '. Zfill (8)
Print U ' 123 '. Isdecimal ()
+ Print U ' aebf '. Isdecimal ()

Result

# python test.py
I am Worker
I am worker
2
1
China
China
True
False
135
1 3 5
1 3 5
3
False
False
True
False
IsDigit False
Islower True
True
False
True
False
1and2and3
123
Abc
Abc
AbAB
(' 1 ', ' 2 ', ' 3 ')
(', ' 1 ', ' 23 ')
(' 12 ', ' 3 ', ')
(' 123 ', ', ')
223
213
2
2
123
(' 1 ', ' 2 ', ' 3 ')
123
[' ', ' 2 ', ' 34 ']
[', ' 2134 ']
[' 1\r ', ' 2\r\n ', ' 3\n ']
[' 1 ', ' 2 ', ' 3 ']
True
123
Ababab
ABC Def Hgj
1aAbB?
00000123
True

False

Finally:

There must be something you need.

Python string method

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.