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'
#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
- Python基础-String字符串
- java基础-字符串String
- Python 字符串 string slicing
- python string unicode字符串
- python字符串string笔记
- python字符串String模块
- Python string字符串
- Python数据类型String字符串
- python string(字符串)
- python—字符串string
- python基础 1: string
- Python 6) 基础 String
- String字符串对象基础详解
- Java基础:字符串之String
- 【Python基础】字符串
- Python<3>字符串基础
- python基础学习 字符串
- python基础之字符串
- CSS概述和选择器及优先级
- 16 增删改查取联系人
- lightoj 1008 - Fibsieve`s Fantabulous Birthday(简单模拟)
- EventBus使用详解
- Android应用程序访问linux驱动第一步:实现并测试Linux驱动
- Python基础-String字符串
- 浅拷贝与深拷贝
- GROUP BY
- eclipse下集成tomcat+maven框架搭建
- 设置UNIX系统文件只读权限
- 2016 ICPC 大连网络赛 HDU 5875 Function
- 第三周项目2- 建设“线性表”算法库
- rest token的一个实现
- MFC----MFC添加excel类库ole库,执行简单读写