Python基础-String字符串

来源:互联网 发布:mysql联合主键怎么设置 编辑:程序博客网 时间:2024/06/07 15:40
#!usr/bin/env/ python
#coding:utf-8


#1.单双引号转义及字符串拼接、前台界面输入


print('hello')
print("word")
print('hello'' word!')
print('hello'+' word')
print('hel\"lo')


'''
name = input('Please input:')
print(name+'!')
'''




#2.字符串格式化d/f/s
pi = 3.1415926
str = 'wangwang'
print('PI=%d'%pi)
print('PI=%5.2f'%pi)
print('string=%s'%str)




#3.字符串方法(find/split/join/strip/lower/replace)
'''
find:在一个较长的字符串中查找子串,他返回子串所在位置最左端索引,如果没有则返回-1
split:将字符串按照一定规则分割成一个列表序列
join:将一个序列按照某种规则拼接成字符串
strip:取出字符串两侧空格
lower:返回字符串小写字母版
replace:替换字符串
'''
title = ' What The fuck off! '
print(title.find('the'))
print(title.find('tthe'))


print(title.split(' '))


list1 = title.split(' ')
sep = '+'
print(sep.join(list1))
print(title)
print(title.strip())


print(title.lower())


print(title.replace('The','is'))


dirs = '','usr','bin'

print('/'.join(dirs))

0 0