Day3-python Study Notes (iv)

Source: Internet
Author: User

String method

#字符串这些方法都不会改变原来字符串的值
name = ' Besttest '
# new_name = Name.strip () #默认是去掉空格和换行符
# new_name = Name.lstrip () #默认是去掉左边的空格和换行符
# new_name = Name.rstrip () #默认是去掉右边的空格和换行符
# new_name = Name.count (' t ') #查找某个字符在字符串里面出现的次数
# index = name.find (' t ') #找到这个字符串, returns its subscript, if not present, returns-1
# index = name.index (' d ') #找到这个字符串, returns its subscript, if not present, error
# Print (Name.upper ()) #把所有字母都变成大写的
# Print (Name.lower ()) #把所有字母都变成小写的
# file_name = ' A.xls '
# Print (File_name.endswith ('. xls ')) #判断一个字符串是否以xx结尾
# sql = ' Select,update,insert,drop,create,alter '
sql = ' select * from User;select '
sql.startswith (' select ') #判断一个字符串是否以xx开头
# f = ' {name} Welcome to age: {age} '
# # print (F.format (name= ' cyan ')) #字符串格式化
# d = {' name ': ' Flynn ', ' Age ':
# Print (F.format_map (d)) #字符串格式化, it goes in a dictionary.
new_sql = sql.replace (' Select ', ' Update ')
# Print (new_sql)
# Print (' 123 '. IsDigit ()) #是否是数字
# Print (' & '. Isalnum ()) #是否包含数字或字母

# st = ' a,b,c,d,f,g '
# st_list = St.split (', ') #字符串分割, returns a list, if nothing is written, is separated by a space
# Print (st_list)

slit = [' A ', ' B ', ' C ', ' d ', ' f ', ' G ']
s2 = ' hhhhhhh '
tu = (' H1 ', ' H2 ', ' H3 ', ' H5 ')
d ={' name ': ' N ', ' age ':
res = ' * '. Join (d) #数组连起来, return string

Print (res)



#可遗忘的
# new_name = Name.capitalize () Capitalize first letter
# Print (Name.center (50, ' * ')) put the string in the middle, with * on both sides
# print (' AaAA '. Islower ()) #是否全是小写字母
# print (' AA '. Isupper ()) #是否全是大写字母
# print (' Sdsad '. Isalpha ()) #是否包含英文字母

Day3-python Study Notes (iv)

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.