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. Unity喷墨效果Shader实现

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  2. Java堆空间溢出解决方法 Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

    一般通过java -jar filename.jar运行jar包,但是当运行的java程序需要较大的内存时,可能会造成堆空间溢出. 例如,加载了几个G大小的json文件,运行报错: Exception ...

  3. python基础第一章

    Python基础 第一个python程序 变量 程序交互 基本数据类型 格式化输出 基本运算符 流程控制if...else... 流程控制-循环 第一个python程序 文件执行 1.用notepad ...

  4. python数据取整

    第三方包:numpy 安装 $ sudo dnf install numpy 4舍6入5取偶 def getInteger(): a = np.float(5.5) # 4舍6入 5取偶 int_a ...

  5. js之选项卡效果(淘宝侧边栏)

    HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  6. C的动态链表建立

    运用到的函数为: 动态内存分配函数malloc()              比如:char *name=(char *)malloc(20);  相当与c++的new关键字 动态内存释放函数free ...

  7. 每天一个linux命令(文件操作):【转载】find命令之xargs

    在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出 ...

  8. BZOJ3444 最后的晚餐【细节题+组合数学】*

    BZOJ3444 最后的晚餐 Description [问题背景] 高三的学长们就要离开学校,各奔东西了.某班n人在举行最后的离别晚餐时,饭店老板觉得十分纠结.因为有m名学生偷偷找他,要求和自己暗恋的 ...

  9. BZOJ1030 JSOI2007 文本生成器 【AC自动机】【DP】*

    BZOJ1030 JSOI2007 文本生成器 Description JSOI交给队员ZYX一个任务,编制一个称之为"文本生成器"的电脑软件:该软件的使用者是一些低幼人群,他们现 ...

  10. 应该抛出什么异常?不应该抛出什么异常?(.NET/C#)

    我在 .NET/C# 建议的异常处理原则 中描述了如何 catch 异常以及重新 throw.然而何时应该 throw 异常,以及应该 throw 什么异常呢? 究竟是谁错了? 代码中从上到下从里到外 ...