Python string method

Source: Internet
Author: User

# name= ' Egon ' #name =str (' Egon ')
# print (type (name))


#优先掌握
# Remove Blank Strip
# msg= ' Hello '
# Print (msg)
# Print (Msg.strip ())

# msg= ' ***hello********* '
# Msg=msg.strip (' * ')
# Print (msg)

# Print (Msg.lstrip (' * '))
# Print (Msg.rstrip (' * '))

#用处
# while True:
# name=input (' User: '). Strip ()
# password=input (' Password: '). Strip ()
#
# if Name = = ' Egon ' and password = = ' 123 ':
# print (' login successfull ')

# splitting split
# info= ' Root:x:0:0::/root:/bin/bash '
# print (info[0]+info[1]+info[2]+info[3])

# user_l=info.split (': ')
# print (user_l[0])

# msg= ' Hello World Egon say Hahah '
# Print (Msg.split ()) #默认以空格作为分隔符

Cmd= ' download|xhp.mov|3000 '
# cmd_l=cmd.split (' | ')
# print (cmd_l[1])
# print (cmd_l[0])

# Print (Cmd.split (' | ', 1))

#用处
# while True:
# cmd=input (' >>: '). Strip ()
# If Len (cmd) = = 0:continue
# Cmd_l=cmd.split ()
# print (' command is: The parameter of%s command is:%s '% (Cmd_l[0],cmd_l[1]))


#
# length Len

# Print (Len (' Hell 123 '))

#
# index

#
# slices: Cut out substrings
# msg= ' Hello World '
# print (Msg[1:3]) #1 2
# print (Msg[1:4]) #1 2 3

# Mastering part
# oldboy_age=84
# while True:
# age=input (' >>: '). Strip ()
# If Len (age) = = 0:continue
# if Age.isdigit ():
# Age=int (age)
# Else:
# print (' must be int ')

#startswith, EndsWith
# name= ' ALEX_SB '
# Print (Name.endswith (' SB '))
# Print (Name.startswith (' Alex '))


#replace
# name= ' Alex Say:i has one tesla,my name is Alex '
# Print (Name.replace (' Alex ', ' SB ', 1))

# print (' My name is%s my "is%s my sex is%s '% (' Egon ', ' Male '))
# print (' My name is ' {} my age was {} My sex is {} '. Format (' Egon ', ' Male '))
# print (' My name is {0} my age is {1} my sex is {0}:{2} '. Format (' Egon ', ' Male ')
# print (' My name ' is {name} my age is {age} my sex is {sex} '. Format (
# sex= ' Male ',
# age=18,
# name= ' Egon '))


# name= ' Goee say hello '
# # Print (Name.find (' S ', 1,3)) #顾头不顾尾, not found then return-1 will not error, found the display index
# # Print (Name.index (' S)) #同上, but could not find an error
#
# Print (Name.count (' S ', 1,5)) #顾头不顾尾, if you don't specify a range, find all


#join
# info= ' Root:x:0:0::/root:/bin/bash '
# Print (Info.split (': '))

# l=[' root ', ' x ', ' 0 ', ' 0 ', ', '/root ', '/bin/bash '
# print (': '. Join (L))


#lower, Upper
# name= ' EGon '
# Print (Name.lower ())
# Print (Name.upper ())

#了解部分
#expandtabs
# name= ' Egon\thello '
# print (name)
# Print (Name.expandtabs (1))


#center, Ljust,rjust,zfill
# name= ' Egon '
# # Print (Name.center (30, '-'))
# Print (Name.ljust (30, ' * '))
# Print (Name.rjust (30, ' * '))
# print (Name.zfill) #用0填充


#captalize, Swapcase,title
# name= ' EGon '
# Print (Name.capitalize ()) #首字母大写, remainder lowercase
# Print (Name.swapcase ()) #大小写翻转
# msg= ' Egon say hi '
# Print (Msg.title ()) #每个单词的首字母大写


#在python3中
Num0= ' 4 '
Num1=b ' 4 ' #bytes
Num2=u ' 4 ' #unicode, Python3 no need to add U is Unicode
num3= ' Four ' #中文数字
num4= ' Ⅳ ' #罗马数字


#isdigt: Str,bytes,unicode
# Print (Num0.isdigit ())
# Print (Num1.isdigit ())
# Print (Num2.isdigit ())
# Print (Num3.isdigit ())
# Print (Num4.isdigit ())

#isdecimal: Str,unicode
# num0= ' 4 '
# num1=b ' 4 ' #bytes
# num2=u ' 4 ' #unicode, Python3 no need to add U is Unicode
# num3= ' Four ' #中文数字
# num4= ' Ⅳ ' #罗马数字
# Print (Num0.isdecimal ())
# # Print (NUM1.)
# Print (Num2.isdecimal ())
# Print (Num3.isdecimal ())
# Print (Num4.isdecimal ())

#isnumeric: Str,unicode, Chinese, Roman
# num0= ' 4 '
# num1=b ' 4 ' #bytes
# num2=u ' 4 ' #unicode, Python3 no need to add U is Unicode
# num3= ' Four ' #中文数字
# num4= ' Ⅳ ' #罗马数字
#
# Print (Num0.isnumeric ())
# # print (NUM1)
# Print (Num2.isnumeric ())
# Print (Num3.isnumeric ())
# Print (Num4.isnumeric ())


#is其他
# name= ' egon123 '
# Print (Name.isalnum ()) #字符串由字母和数字组成
# name= ' Asdfasdfa SDF '
# Print (Name.isalpha ()) #字符串只由字母组成
#

# name= ' asdfor123 '
# Print (Name.isidentifier ())
Name= ' Eggon '
Print (Name.islower ())
# Print (Name.isupper ())
# Print (Name.isspace ())
Name= ' Egon say '
Print (Name.istitle ())

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.