1、rstrip()删除末尾指定字符串

例如:A = '1,2,3,4,5,'

   B = A.rstrip(',')

   B = '1,2,3,4,5'

2、isdigit()方法

Python isdigit() 方法检测字符串是否只由数字组成,返回 True 或者False。

例如:str = '123456'

   str.isdigit()为True

3、enumerate() 函数

enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。

例如:seq = ['one', 'two', 'three']

   for i, element in enumerate(seq):

     print i, element

输出:0 one

   1 two

   2 three

4、字符串 startswith、find、join

例如:name = 'Swaroop'

   if name.startswith('Swa'):  #startswith方法用于查找字符串是否以给定的字符串内容开头

    print('the string start with "Swa"')

   if 'a' in name:

    print('it contains the string "a"')

   if name.find('war') !=-1:  #find方法用于定位字符串中给定字符串的位置,如果找不到对应的字符串,会返回-1

    print('it contains the string "war"')

   delimiter = '_*_'

   mylist = ['Brazil','Russia','India','China']

   print(delimiter.join(mylist))  #字符串delimiter将会作为每个项目之间的分隔,并以此返回一串更大的字符串

输出:the string start with "Swa"

   it contains the string "a"

   it contains the string "war"

   Brazil_*_Russia_*_India_*_China

5、函数传递元组,返回多个变量

例如:def run():

    return ('hello','world')

   first, second = run()

   print(first)

   print(second)

输出:hello

   world

6、在函数中接收元组与字典

分别使用 * 或 ** 作为元组或字典的前缀,来使它们作为一个参数为函数所接收

例如:def powersum(power, *args):

    total = 0

    for i in args:total += pow(i, power)

    return total

   print(powersum(2, 3, 4))

   print(powersum(2, 10))

输出:25

   100

最新文章

  1. Python检查xpath和csspath表达式是否合法
  2. JS策略模式
  3. Scrum项目8.0
  4. Codeforces Round #389 Div.2 A. Santa Claus and a Place in a Class
  5. Java Web整合开发实战:基于Struts 2+Hibernate+Spring 目录
  6. GTP (GPRS隧道协议(GPRSTunnellingProtocol))
  7. C语言 类型
  8. Oracle 临时表
  9. 《javascript高级程序设计》第六章 Object Creation VS Inheritance
  10. C#EasyHook例子C# Hook 指定进程C#注入指定进程 z
  11. Moses manual 中Basline System 2.3.4节用IRSTLM创建语言模型的命令有误
  12. ASP.NET网站实现中英文转换(本地化资源)
  13. ldap命令的使用
  14. 读headFirst设计模式 - 观察者模式
  15. 使用Myeclipse2015构建SpringMVC项目
  16. [BZOJ3011][Usaco2012 Dec]Running Away From the Barn
  17. 什么是mime类型
  18. scrapy 是指user_agent
  19. jq插件封装格式
  20. [Android Pro] Android中IntentService的原理及使用

热门文章

  1. bzoj 3745: [Coci2015]Norma【分治】
  2. spring boot :error querying database. Cause: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required
  3. C++伪函数
  4. 洛谷 P2398 GCD SUM || uva11417,uva11426,uva11424,洛谷P1390,洛谷P2257,洛谷P2568
  5. Retrofit实现PUT网络请求,并修改Content-Type
  6. 对js 面对对象编程的一些简单的理解
  7. LN : leetcode 516 Longest Palindromic Subsequence
  8. 一份最贴近真实面试的Java基础面试题
  9. 设置QtreeWidget水平滚动条
  10. powerDesigner 把name项添加到注释(comment),完美方案!