Python字符串重点函数

#! /usr/bin/env python

# -*- coding:utf-8 -*-

# join      # '_'.join("asdfasdf")

# split

# find

# strip

# upper

# lower

# replace

###################### 7个常用string ######################

#join以什么连接字符串

# n1 = 'dsada'

# n2 = '_'

# v = n2.join(n1)

# print(v)

# ----------------------

# split分割符 以什么分割,分割成几份

# n1 = 'timetimetime'

# v = n1.split('t' , 3)

# print(v)

# ----------------------

# find 从开始往后找,找到第一个之后,获取其未知

# n1 = 'timetimetime'

# v = n1.find('me')

# print(v)

# ----------------------

# strip 移除左右空白

# n1 = '    timetimetime    '

# v = n1.strip()

# print(v)

# ----------------------

# upper小写转换成大写

# n1 = 'timetimeTime'

# v = n1.upper()

# print(v)

# ----------------------

# lower大写转成小写

# n1 = 'timetimeTime'

# v = n1.lower()

# print(v)

# ----------------------

# replace替换字符串(区分大小写)

# n1 = 'timetimeTime'

# v = n1.replace('time' , 'wentian')

# print(v)

###################### 4个灰魔法######################

# for 变量名 in 字符串:

#    变量名

# break

# continue

# text = 'mianshigual'

# for itme in text:

#    print(itme)

#索引,下标,获取字符串中的某一个字符

# text = 'mianshigual'

# v = text[3]

# print(v)

#切片 取索引为0-4的字符

# text = 'mianshigual'

# v = text[0:4]

# print(v)

#len 获取长度 len获取当前字符串中由几个字符组成

# text = 'mianshigual'

# v = len(text)

# print(v)

#获取连续或不连续的数字

# Python2中直接创建在内容中

# python3中只有for循环时,才一个一个创建

# r1 = range(10)

# r2 = range(1,10)

# r3 = range(1,10,2)

# 帮助创建连续的数字,通过设置步长来指定不连续

# v = range(0, 100, 5)

#

# for item in v:

#    print(item)

# n1 = range(10)

# print(n1)

#

# n2 = range(0 , 10 , 3)

# print(n2)

#

# for itme in n2:

#    print(itme)

##### 练习题:根据用户输入的值,输出每一个字符以及当前字符所在的索引位置#####

# n1 = input('>>>>')

# #打印字符串

# for itme in n1:

#    print(itme)

#获取字符串的长度

# v = range(0 , len(n1))

#

# for itme in v:

#    print(itme , n1[itme]) #打印字符串对应索引

# for itme in range(0 , len(n1)):

#    print(itme , n1[itme])

###################### 1个深灰魔法######################

# 字符串一旦创建,不可修改

# 一旦修改或者拼接,都会造成重新生成字符串

# name = "zhengjianwen"

# age = "18"

#

# info = name + age

# print(info)

你可能感兴趣的:(Python字符串重点函数)