python 字符串常用方法

name = 'xiaogou.jpg'
# print(name.count('i')) #找某个元素出现的次数
# print(name.index('A'))  #找下标
# print(name.find('A'))  #找下标

# print(name.strip('.')) #默认去掉换行符和空格
# print(name.rstrip())
# print(name.lstrip())

# print(name.startswith('xiaogou')) #判断是否以xx开头
# print(name.endswith('.jpg')) #判断是否以xxx结尾
# print(name.isdigit()) #判断这个字符串里面是不是都是整数

#这几个方法有点印象就行
# print(name.islower()) #判断这个字符串是不是小写
# print(name.isupper()) #
# print(name.isspace()) #判断是否为空格
# print(name.isalnum()) #只要字符串里面没有特殊字符就返回true
# print(name.isalpha()) #里面如果只有中文或者字母的话,返回true
# print(name.capitalize())  #首字母大写

# name = 'Hello World!'
# # print(name.zfill(5)) #补零的
# new_name = name.replace('o','O')
# print('replace..',new_name) #替换
# print('name.',name)
#
# print(name.upper()) #大写
# print(name.lower()) #小写

# stus='xiaoming     xiaohei xiaobai'
# result = stus.split()
# print(result)

names = ['1','2','3','4','5']
s2 = '123'
result = ','.join(names)
print(result)

# xiaoming,xiaohei,xiaobai
# s=''
# for name in names:
#     s=s+name+'  '
# print(s.strip())



你可能感兴趣的:(python)