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))
#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))
相关文章推荐
- 【Python】基础学习——列表(list),元祖(tuple),字典(dict),字符串(string),集合(set)
- Python基础:数据类型-字符串:string
- python基础数据结构——列表(list), 元祖(tuple), 字典(dict), 字符串(string), 集合(set) 介绍及相互转换
- 4-Python3从入门到实战—基础之数据类型(字符串-String)
- Python 基础之字符串string详解及实例
- Python基础数据类型-字符串(string)
- python基础学习——列表(list), 元祖(tuple), 字典(dict), 字符串(string), 集合(set) 介绍及相互转换
- Python基础--变量定义、字符串切片及编码
- JavaSE8基础 String indexOf 正向 从指定索引值开始查找 字符在字符串中第一次出现的位置
- JavaSE8基础 String isEmpty 判断字符串的内容值是否为空
- JavaSE8基础 Arrays.toString 将一维int数组转成字符串输出
- python string字符串的8种连接方式
- Python列表(list)、字典(dict)、字符串(string)基本操作小结
- Python基础:03序列:字符串、列表和元组
- 黄聪:Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- Python3基础 int()把合格字符串转化成整数
- python字符串和变量相加时出现,coercing to unicode need string or buffer nonetype found python 错误的解决
- Python3基础 str lstrip 去掉字符串左边的空格
- python基础知识--字符串
- 自学Python之Python基础:(一)数字、字符串和变量