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永远不会粘包 你的程序实际上无权直接操作网卡的,你操作网卡都是通过操作系统给用户程序暴露出来的接口,那每次你的程序要给远程发数据时,其实是先把数据从用 ...
随机推荐
- asp.net Npoi 使用
HSSFWorkbook hssfworkbook = new HSSFWorkbook(); //增加 ExcelNPOI.SS.UserModel.ISheet SheetName = hssfw ...
- Scikit-learn方法使用总结
在机器学习和数据挖掘的应用中,scikit-learn是一个功能强大的python包.在数据量不是过大的情况下,可以解决大部分问题.近期在学习使用scikit-learn的过程中,我自己也在补充着机器 ...
- linux uname和dpkg命令
uname -a:查看系统一些参数 dpkg -i:安装下载好的.deb包裹
- U盘传送容量与格式问题
问题 今天想将7.6G的文件拷到U盘里,提示u盘内存不足,其实内存为14+G. 解答 U盘格式对于U盘的传送大小有限制 下面为U盘三种不同格式的应用及优缺点 FAT32格式:为系统默认格式,具有极佳的 ...
- 学校项目过程中知识点 Java 2015/9/15 晚
##命令行运行Java程序1.文件Java的源代码存放在扩展名为“.java”的文件中:Java源文件编译后,得到“.class”的文件2.方法命令行下编译java源代码的方法:javac 文件名. ...
- [译]贵宾犬咬伤了TLS
原文链接:https://community.qualys.com/blogs/securitylabs/2014/12/08/poodle-bites-tls 原文发表时间:2014.12.8 今天 ...
- JS 区分单击双击
var timeout =null; $("#Btn").on("click",function(){ clearTimeout(timeout);//停止单击 ...
- LaTex初学
先用三句话来介绍什么是LaTeX:1.LaTeX是一类用于编辑和排版的软件,用于生成PDF文档.2.LaTeX编辑和排版的核心思想在于,通过\section和\paragraph等语句,规定了每一句话 ...
- Java8新特性——StreamAPI(一)
1. 流的基本概念 1.1 什么是流? 流是Java8引入的全新概念,它用来处理集合中的数据,暂且可以把它理解为一种高级集合. 众所周知,集合操作非常麻烦,若要对集合进行筛选.投影,需要写大量的代码, ...
- 完美解决github访问速度慢[转]
1. 修改本地hosts文件 windows系统的hosts文件的位置如下:C:\Windows\System32\drivers\etc\hosts mac/linux系统的hosts文件的位置如下 ...