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. 关于windows完成端口(IOCP)的一些理解

    本人很多年前接触完成端口以来,期间学习和练习了很多次,本以为自己真正地理解了其原理,最近在看网狐的服务器端源码时又再一次拾起完成端口的知识,结果发现以前理解的其实很多偏差,有些理解的甚至都是错误的.网 ...

  2. Ubuntu16.04 --> 14.04

    从16到14 自认为14是比较稳定的.从安装依赖上说. 14安装应用 更多参见[请直接拉到"华丽丽的分割线"下面] Java9 注意,添加源的时候先把lantern打开!!! 添加 ...

  3. Hive SQL的编译过程[转载自https://tech.meituan.com/hive-sql-to-mapreduce.html]

    https://tech.meituan.com/hive-sql-to-mapreduce.html Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hi ...

  4. js去重复和取重复数据

    js数组中取重复数据的方法: 方法一:去重复数据 <script> Array.prototype.distinct=function(){ var a=[],b=[]; for(var ...

  5. Lua在Linux下的安装

    转载于:http://blog.csdn.net/aizquan/article/details/21190393 本来这个很简单,但常常会偶尔会有问题,也记不住,所以就直接转下来,以后方便遇到的时候 ...

  6. apiman 安装&&使用

    安装测试基于docker 1. docker  image pull   docker pull apiman/on-wildfly1   2. 启动   docker run -d -p 8081: ...

  7. [LeetCode系列]翻转链表问题II

    给定一个链表和两个整数m, n, 翻转链表第m个节点到第n个节点(从1开始计数). 如, 给定链表: 1->2->3->4->5->NULL, 以及 m = 2, n = ...

  8. 搭建一个IntelliJ的Spark项目

    之前发现创建一个新项目之后,无法添加scala class 创建新项目 选择maven项目,然后选择simple或者quickstart: 进入项目后,在Project Structure里面,在gl ...

  9. promise的学习心得记录

    这里只讲promise,和async的使用方法,不会讲他们的原理. Promise 是异步编程的一种解决方案,可以用于取代传统的回调函数,该变那些函数层层嵌套调用的尴尬局面. 1)promise 基本 ...

  10. ESP8266编译过程探索

    首先看到的是为什么SDK里有一个libmain.a这样的库. 编译之后才发现原平是这样子:main函数(如果有的话)会调用我们user_init函数.user_rf_cal_sector_set函数, ...