python数据类型常用内置函数之字符串
1、strip, lstrip, rstrip
x = ' jiahuifeng '
print(x.strip(' '))
print(x.lstrip(' '))
print(x.rstrip(' '))
2、lower ,upper
x = 'jiahuifeng'
print(x.lower())
print(x.upper())
3、startswith,endswith
x = 'fengjiahui_haha'
print(x.startswith('fe'))
print(x.endswith('_haha'))
4、格式化输出
print('My name is %s,my age is %s' %('jiahuifeng',18))
print('{} {} {}'.format('jiahuifeng',18,'male'))
5、split , splitlines
name='root:x:0:0::/root:/bin/bash'
print(name.split(':')) #默认分隔符为空格 name='C:/a/b/c/d.txt' #只想拿到顶级目录
print(name.split('/',1)) name='a|b|c'
print(name.rsplit('|',1)) #从右开始切分 name = '''ab c
de fgkl
sadfewf'''
print (name.splitlines())
6、join
name=' '
print(tag.join(['egon','say','hello','world'])) -->egon say hello world
7、replace
name='jiahuifeng say :i have one apple,my name is jiahuifeng'
print(name.replace('jiahuifeng','qiqi',1))
8、拼接
x = 'jiahuifeng'
y = 'shi'
z = 'haha' name = x+y+z
print(name)
python数据类型常用内置函数之字符串的更多相关文章
- Python的常用内置函数介绍
Python的常用内置函数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.取绝对值(abs) #!/usr/bin/env python #_*_coding:utf-8_ ...
- python中常用内置函数和关键词
Python 常用内置函数如下: Python 解释器内置了很多函数和类型,您可以在任何时候使用它们.以下按字母表顺序列出它们. 1. abs()函数 返回数字的绝对值. print( abs(-45 ...
- Python数据类型的内置函数之str(字符串)
Python数据类型内置函数 - str(字符串) - list(列表) - tuple(元组) - dict(字典) - set(收集) str(字符串)的一些操作 - 字符串相连方法 # 字符串的 ...
- python之常用内置函数
python内置函数,可以通过python的帮助文档 Build-in Functions,在终端交互下可以通过命令查看 >>> dir("__builtins__&quo ...
- Python数据类型的内置函数之tuple(元组),dict(字典),set(集合)
Python数据类型内置函数 - str(字符串) - list(列表) - tuple(元组) - dict(字典) - set(收集) tuple(元组)的操作 - (count)统计元组中元素出 ...
- Python数据类型的内置函数之list(列表)
Python数据类型内置函数 - str(字符串) - list(列表) - tuple(元组) - dict(字典) - set(收集) list(列表)的操作 - (append)在列表最后追加指 ...
- python中常用内置函数用法总结
强制类型转换:int()float()str()list()tuple()set()dict()总结,这几种类型转换函数得用法基本一致,基本就是int(要转换得数据).返回值类型为对应得数据类型 ...
- PYTHON语言之常用内置函数
一 写在开头本文列举了一些常用的python内置函数.完整详细的python内置函数列表请参见python文档的Built-in Functions章节. 二 python常用内置函数请注意,有关内置 ...
- Python常用内置函数介绍
Python提供了一个内联模块buildin.内联模块定义了一些开发中经常使用的函数,利用这些函数可以实现数据类型的转换.数据的计算.序列的处理等功能.下面将介绍内联模块中的常用函数. Python内 ...
随机推荐
- caffe从入门到放弃
断断续续折腾ML近一年,写点博客记录这个坑.
- C++ 动态多维数组的申请与释放
今天在实验室的项目中遇到了一个问题,直接上代码: void ViBe::init(Mat img) { imgcol = img.cols; imgrow = img.rows; // 动态分配三维数 ...
- B. Simple Molecules
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- B. Chris and Magic Square
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- hdoj1596【spfa,松弛】
积压很久的一道...一看直接spfa水过..但是看那个safest怎么求得?松弛的时候取大. #include <bits/stdc++.h> using namespace std; t ...
- bzoj 1879: [Sdoi2009]Bill的挑战【状压dp】
石乐志写容斥--其实状压dp就行 设f[i][s]表示前i个字母,匹配状态为s,预处理g[i][j]为第i个字母是j的1~n的集合,转移的时候枚举26个字母转移,最后答案加上正好有k个的方案即可 #i ...
- combobox级联检索下拉选择框
1.效果图 2.前端 @{ ViewBag.Title = "Index"; Layout = null; @*自动筛选下拉框*@ <script src="~/S ...
- 初识Sklearn-IrisData训练与预测
笔记:机器学习入门---鸢尾花分类 Sklearn 本身就有很多数据库,可以用来练习. 以 Iris 的数据为例,这种花有四个属性,花瓣的长宽,茎的长宽,根据这些属性把花分为三类:山鸢尾花Setosa ...
- IDEA thymeleaf ${xxx.xxx}表达式报错,红色波浪线
解决方法: 在<!DOCTYPE html>标签下面加上 <!--suppress ALL--> 代码如图: 不再报错,效果如下图:
- Luogu P2278 [HNOI2003]操作系统【优先队列/重载运算符/模拟】 By cellur925
题目传送门 本来是照着二叉堆的题去做的...没想到捡了个模拟...不过模拟我都不会...我好弱啊... 其实核心代码并不长,比辰哥的标程短到不知哪里去...但是思路需要清晰. 读题的时候我明白,当有优 ...