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的更多相关文章

  1. Python strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的

    在python中,strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的对象. a = 1 def fun(a):     a = 2 fun(a ...

  2. Python中文乱码

    1,注意:请使用智慧型浏览器 "CHROME" 配合理解和运作本文中提到的程序. 2,提示:谷歌的CHROME浏览器是迄今为止最智慧的浏览器,没有之一,只有第一. 3,谷歌的CHR ...

  3. Python相关工具清单[持续更新]

    SublimeJEDI : awesome Python autocompletion with SublimeText. Awesome Python : A curated list of awe ...

  4. The internals of Python string interning

    JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A fe ...

  5. 浅析Python中的struct模块

    最近在学习python网络编程这一块,在写简单的socket通信代码时,遇到了struct这个模块的使用,当时不太清楚这到底有和作用,后来查阅了相关资料大概了解了,在这里做一下简单的总结. 了解c语言 ...

  6. (转)python struct简介

    最近在学习python网络编程这一块,在写简单的socket通信代码时,遇到了struct这个模块的使用,当时不太清楚这到底有和作用,后来查阅了相关资料大概了解了,在这里做一下简单的总结. 了解c语言 ...

  7. Python: 在Unicode和普通字符串之间转换

    Unicode字符串可以用多种方式编码为普通字符串, 依照你所选择的编码(encoding): <!-- Inject Script Filtered --> Toggle line nu ...

  8. 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 ...

  9. python socket网络编程之粘包问题详解

    一,粘包问题详情 1,只有TCP有粘包现象,UDP永远不会粘包 你的程序实际上无权直接操作网卡的,你操作网卡都是通过操作系统给用户程序暴露出来的接口,那每次你的程序要给远程发数据时,其实是先把数据从用 ...

随机推荐

  1. Python 使用 os.fork() 创建子进程

    Linux 操作系统提供了一个 fork() 函数用来创建子进程,这个函数很特殊,调用一次,返回两次,因为操作系统是将当前的进程(父进程)复制了一份(子进程),然后分别在父进程和子进程内返回.子进程永 ...

  2. 解决tensorflow的Session Exception问题

    Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.S ...

  3. ubuntu 终端命令颜色的修改

    http://blog.chinaunix.net/uid-13954789-id-3137184.html http://blog.chinaunix.net/uid-26021340-id-348 ...

  4. js之广告弹出自动关闭

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  5. ios 控制器的生命周期

    #pragma mark - 控制器生命周期 // 视图将要出现 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:anima ...

  6. 每天一个linux命令:【转载】tail命令

    tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...

  7. 每天一个linux命令:【转载】mv命令

    mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录. 1.命令格式: mv [选项] 源文件或目 ...

  8. JavaScript中字符串截取函数slice()、substring()、substr()

    在js中字符截取函数有常用的三个slice().substring().substr()了,下面我来给大家介绍slice().substring().substr()函数在字符截取时的一些用法与区别吧 ...

  9. oracle-分区(笔记)

    partition by 用于指定分区方式 range 表示分区的方式是范围划分 partition pn 用于指定分区的名字 values less than 指定分区的上界(上限) ------- ...

  10. 《selenium2 python 自动化测试实战》(18)——自动化测试模型(一)

    线性测试 已经被淘汰了:线性测试就是一个脚本完成一个场景,代码基本没有复用,每一个脚本都要从头开始写——这哪行. 模块化与类库 这个就是分模块:有点类似面系那个对象,把功能(比如登录)单独拿出来,当下 ...