您的位置:首页 > 编程语言 > Python开发

Python基础-String字符串

2016-09-12 19:33 344 查看
#!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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐