Python Strings
1. Basic
#Python treats single quotes the same as double quotes.
var = 'haha'
var = "666"
2. accessing
var = 'haha'
var[0] #'h'
var[1:3] #'ah'
3. Updating
We can update a string with a variable.
The variable can be a new string or some part of the old string and new string.
var = '123'
var = var[:1]+'46'
4. Built-in string method
str = 'hello'
str.capitalize() #It returns a copy of the string with only its first character capitalized.
#str = 'Hello
str = 'hello'
str.center(width, fillchar) #The method center() returns centered in a string of length width. Padding is done using the specified fillchar. Default filler is a space.
#str.center(7, 6)
#str = '6hello6' str.count(sub, start= 0,end=len(string))
#the method count() returns the number of occurrences of substring sub in the range [start, end].
#sub -- substring
#start -- default is 0
#end str.find(str, beg=0, end=len(string))
#Determine if str occurs in string or in a substring of string if starting index beg and ending index end are given returns index if found and -1 otherwise. str.isalnum() #Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise. alphabetic+numeric str.isalpha() #Returns true if string has at least 1 character and all characters are alphabetic and false otherwise. str.isdigit() #Returns true if string contains only digits and false otherwise. str.islower() #Returns true if string has at least 1 cased character and all cased characters are in lowercase and false otherwise. str.isupper()
Python Strings的更多相关文章
- Python strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的
在python中,strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的对象. a = 1 def fun(a): a = 2 fun(a ...
- Python中文乱码
1,注意:请使用智慧型浏览器 "CHROME" 配合理解和运作本文中提到的程序. 2,提示:谷歌的CHROME浏览器是迄今为止最智慧的浏览器,没有之一,只有第一. 3,谷歌的CHR ...
- Python相关工具清单[持续更新]
SublimeJEDI : awesome Python autocompletion with SublimeText. Awesome Python : A curated list of awe ...
- The internals of Python string interning
JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A fe ...
- 浅析Python中的struct模块
最近在学习python网络编程这一块,在写简单的socket通信代码时,遇到了struct这个模块的使用,当时不太清楚这到底有和作用,后来查阅了相关资料大概了解了,在这里做一下简单的总结. 了解c语言 ...
- (转)python struct简介
最近在学习python网络编程这一块,在写简单的socket通信代码时,遇到了struct这个模块的使用,当时不太清楚这到底有和作用,后来查阅了相关资料大概了解了,在这里做一下简单的总结. 了解c语言 ...
- Python: 在Unicode和普通字符串之间转换
Unicode字符串可以用多种方式编码为普通字符串, 依照你所选择的编码(encoding): <!-- Inject Script Filtered --> Toggle line nu ...
- Python 3.5.1 Syntax & APIs(Continue Updating..
print(x, end=' ') instead of print(x) to escape the default line-changing-output. print(str.ljust(si ...
- python socket网络编程之粘包问题详解
一,粘包问题详情 1,只有TCP有粘包现象,UDP永远不会粘包 你的程序实际上无权直接操作网卡的,你操作网卡都是通过操作系统给用户程序暴露出来的接口,那每次你的程序要给远程发数据时,其实是先把数据从用 ...
随机推荐
- Gradle2.0用户指南翻译——第一章. 介绍
翻译项目请关注Github上的地址:https://github.com/msdx/gradledoc本文翻译所在分支:https://github.com/msdx/gradledoc/tree/2 ...
- 随手一写就是一个侧滑关闭activity
刚忙完一段时间,今天刚清闲会,就把以前写的东西整理整理.于是冥冥中发现有些东西完全可以共享出来,毕竟那么常见,而且简单实用. 实现原因 其实侧滑关闭activity在网上也有大量的文章去介绍他,我也有 ...
- iOS怎么来实现关闭自动锁屏
怎么来设置[UIApplication sharedApplication] idleTimerDisabled 属性来控制自动锁屏的效果 // 把设置idleTimerDisabled的代码放到 ...
- laravel 中禁用掉注册功能
想让 laravel 做单用户登录,禁止掉注册功能 在 RegisterController 添加以下方法 public function showRegistrationForm() { retur ...
- BZOJ1101 POI2007 Zap 【莫比乌斯反演】
BZOJ1101 POI2007 Zap Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b, ...
- 《DSP using MATLAB》示例Example6.6
代码: h = [1, 2, 3, 2, 1]/9; [C, B, A] = dir2fs(h) 运行结果:
- 我常用的几个第三方 Python 库
转自:http://blog.csdn.net/gzlaiyonghao/article/details/2966811 wxPython 如果你之前是 windows 程序员,用 MFC 或者 WI ...
- goreman 多进程管理工具
Linux下多进程管理工具对开发和运维都很有用,常见的功能全面的主流工具主要有monit.supervisor.不过开发中使用则推荐轻量级小工具goreman 举个例子:coreos的etcd就是使用 ...
- Ubuntu 16.04 配置安卓5.1编译环境
Ubuntu 16.04版本 电脑cpu必须是64位 硬盘分配大约100G的空间 1.ubuntu中更新源 $ sudo apt-get update 2.安装 openjdk-8-jdk $ sud ...
- Python--线性代数篇
讲解Python在线性代数中的应用,包括: 一.矩阵创建 先导入Numpy模块,在下文中均采用np代替numpy import numpy as np 矩阵创建有两种方法,一是使用np.mat函数或者 ...