1.字符串常用操作(较多,用代码加注释表示) name = '\tMy name is congcong' print(name.capitalize())#输出结果为 My name is congcong(首字母大写) print(name.count('n')) #输出结果为 3(统计) print(name.center(30,'-')) #输出结果为 -----My name is congcong------(一共打印30个字符,并将字符串放中间) print(name.encode…
Python是什么 Python是著名的"龟叔"Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. 创始人Guido van Rossum是BBC出品英剧Monty Python's Flying Circus(中文:蒙提·派森的飞行马戏团)的狂热粉丝,因而将自己创造的这门编程语言命名为Python. 人生苦短,我用python,翻译自"Life is short, you need Python" Python英式发…
1.os.name 输出字符串指示正在使用的平台.如果是window 则用'nt'表示,对于Linux/Unix用户,它是'posix' import os print(os.name) #结果如下 nt 2.os.getenv() 获取系统的环境变量 import os result = os.getenv("PATH") print(result.split(':')) #结果如下 ['D', '\\work_software\\Python3.6\\lib\\site-packa…
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This PEP proposes a new system for built-in string formatting operations, intended as a replacement for the existing '%' string formatting operator. 1.百分号…
python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况 any any(iterable) Return True if any element of the iterable is true. If the iterable is empty, return False 如果序列中任何一个元素为True,那么any返回True.该函数可以让我们少些一个for循环.有两点需要注意 (1)如…