栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

大数据之路-------python基础(一)

大数据之路-------python基础(一)

1、字符串函数

test_str='   CHINA  '

去除字符串前后制表符空格:test_str.strip()  >> 'CHINA'

去除字符串左边制表符空格:test_str.lstrip()  >>  'CHINA  '

去除字符串右边制表符空格:test_str.rstrip()  >>  '   CHINA'

test_str='china'

字符串所有变大写:test_str.upper()  >>  'CHINA'

test_str='CHINA'

字符串所有变小写:test_str.lower()  >>  'china'

test_str='china'

字符串首字母变大写:test_str.capitalize  >>  'China'

test_str='i love china'

字符串所有单词首字母大写:test_str.title()  >> 'I Love China'

test_str='CHINA'

字符串判断是否全部大写:test_str.isupper()  >> True

字符串判断是否全部小写:test_str.islower() >> False

test_str=1234a

字符串判断是否全部数字:test_str.isdigit() >> False

test_str='CHINA'

字符串判断开头字符串是否相等:test_str.startswith('CHI')   >>   True

test_str='CHINA'

字符串判断结尾字符串是否相等:test_str.endswith('NB')   >>  False

password='123'

input_password='123456789'

查找字符串在另一字符串所在位置:

input_password.find(input_password)    >>   3   (如果没找到返回-1)

input_password.index(input_password)  >>  3   (如果没找到直接报错)

计算字符串在另一字符串里的个数:

input_password.count('3')   >> 1

替换字符串:

‘abce’.replace('a','b')  >> 'bbce'

'apple orange'.replace('apple','banana')  >> 'banana orange'

计算字符串长度:

len(password)  >>  3

2、元组(元组是不可变序列)

t = tuple('python')  >>  t ->  ('p','y','t','h','o','n')

t =  ('p','y','t','h','o','n') >> t ->  ('p','y','t','h','o','n')

t = ('My','age','is',19) >> t -> ('My','age','is',19)

t = 'My','age','is',19 >>  t -> ('My','age','is',19)    t[0] -> 'My'    t[0,2] -> ('My','age')

t = ('Solo',) >> t -> (Solo,)

t = 'Solo', >>  t -> (Solo,)   //元组括号可加可不加,但是元组中只有一个元素时后面必须要加逗号

t = ('My','age','is','19') >> ' '.join(t) -> My age is 19      '+'.join(t) -> My+age+is+19

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/673946.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号