1.1 python字符串定义 #!/usr/bin/python # -*- coding: utf8 -*- # 定义一个字符串 s1 = 'this is long String that spans two lines' # 表示下面一行是上一行的延续 s2 = 'this is long String\ that spans two lines' #原样输出字符串 s3 = """this is long String that spans two lines &q
Python中定义常量 都用大写 Pip 安装python第三方模块的命令 一般默认都放在/python27/lib/site-pak List.count(‘元素’)-------------统计list中有几个相同的元素 List.index(‘元素’)---------返回当前(第一个出现的)元素的下标 通过下标来修改list中的相同的值 for i in range(lis.count(90)): nn = lis.index(90) lis[nn] = 999999999
1.首字母大写 语法:S.capitalize() -> str title = "today is a good day" title_ca = title.capitalize() print(title_ca) 结果:today is a good day 2.大写转小写 语法:S.casefold() -> str title = "TODAY is a GOOD day" title_ca = title.casefold() print(ti
看了一些网上的解释,最主流的解释是“str是给人看的,repr是给机器看的”,如果已经理解了的,这句话是对的,但是是有问题的,对于没懂的,这句话是无法理解的. 我来尝试解释一下.先直译一下官方文档: repr(object) Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string tha