Python基础 6.字符串定义与操作

#\n   换行注释可表示多行信息输出
\t制表
print内三层注释用于表示多行信息输出

print('566')

"""
#
\n   换行注释可表示多行信息输出
\t制表
print内三层注释用于表示多行信息输出
print('asd fgh \ mm')

print('asd fgh \n mm')

print('asd fgh \t mm')
"""

"""
asd fgh \ mm
asd fgh
 mm
asd fgh          mm
"""



#字符串大小写转换 .lower() .lower()函数,

startswith(被判断对象)判断字符串的开始,endswith(字符)判断是否包含字符结束

"""
#字符串大小写转换 .lower() .lower()函数
sp='hello lindar  1 2 3 4 5 6'
print(sp[-1])
print(sp[0:5])
sp1=sp.upper()
print(sp1)
sp2=sp.lower()
print(sp2)
print(sp2.isupper())

print(sp.startswith('he'))
print(sp.endswith('8'))
"""

"""
6
hello
HELLO LINDAR  1 2 3 4 5 6
hello lindar  1 2 3 4 5 6
False
True
False
"""


#字符串函数 :join split。可将字符串列表转换为字符串函数

#split()函数还原#rjust() ljust()对齐方法

#删除空白字符  strip 删除两边空格,lstrip()删除左边空格,lstrip删除右边

 

#字符串函数 :join split。可将字符串列表转换为字符串函数
"""
#join()函数在每个字符串中间加入字符
>>> ','.join(['a','s','d'])
'a,s,d'
>>> ' '.join(['a','s','d'])
'a s d'
>>> 
#split()函数还原
>>> 'a s d f'.split()
['a', 's', 'd', 'f']
>>> 'acscdcf'.split('c')
['a', 's', 'd', 'f']
#rjust() ljust()对齐方法
>>> sp.rjust(20)
'            absulote'
>>> sp.ljust(20)
'absulote           '  
>>> sp.center(20,'-')
'------absulote------'
>>> sp.rjust(20,'+')
'++++++++++++absulote'
#删除空白字符  strip 删除两边空格,lstrip()删除左边空格,lstrip删除右边
>>> sp='           abc               '
>>> sp.strip()
'abc'
>>> sp.lstrip()
'abc     
>>> sp='asdfga'
>>> sp.strip()
'asdfga'
#指定字符串可删除
>>> sp.strip('a')
'sdfg'
>>>           '

"""
 

 

实例

"""
import pyperclip
pyperclip.copy('abc123')
sp=pyperclip.paste()
print(sp)

passwords={'a':'1254191758','b':'excelenter','c':'8'}

import sys,pyperclip
#print(sys.argv[1]) #路径表达式
 
if len(sys.argv)<2 :
    print('Usage :python t6.py [account] - copy account password')
    sys.exit()
    
     
account ='c'
if account in passwords:
    pyperclip.copy(passwords[account])
    print('password has copyed'+account)
else :
    print('no account'+account)


"""
"""
566
abc123
Usage :python t6.py [account] - copy account password
"""


 

"""
#无序列表,分离行
import pyperclip
 
t=pyperclip.paste()


 
line=t.split('\n')
 
for i in range (len(line)):
    line[i]='*' +line[i]
    print(line[i])

t=pyperclip.copy(t)
print(t)
"""

"""
*line=t.split('\n')
*for i in range (len(line)):
*    line[i]='*' +line[i]
*
*pyperclip.copy(t)
None

""


 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值