如何使用字符串

lst = eval(input('请输入列表lst:'))
list1=set(lst)
print(list1)                     
    {'1', '2', '3'}
    
#lst。。。接受列表输入。
#输入列表,输出不带重复数字的列表

dict = {'fhz': '27', 'ljd': '28', 'hyx': '4'}  
print("dict['fhz']:",dict['fhz'])
    dict['fhz']: 27
dict1 = {'key1': '27', 'key2': '28', 'key3': '4'}  
dict2 = {'value1': 'fhz','value2': 'ljd','value': 'hyx'}
import random
print("dict1['key1']:",dict['key1'])

创建字符串

str1 = 'hello'## str2 = "world"
str3 = """ni hao"""

查询字符串

str1[0:6:2]
    'hlo'
str1[-3:-1]
  'll'

删除字符串

#str1.replace
str4 = ' ',join([strl,strl2])
str4
str4.split(' ')   #split可把字符串拆成字符
print('')
str5 = 'hello\n'
print(str5.strip())     #strip可删除分隔符
f = open('test.txt', 'w'#建立一个链接
f.write("hello world\n")      #已在内存中运行
f.write("I'm here")
f.close()    #执行
f = open('test.txt','r')
f.read(1)
lines = f.readlines()        #逐行读入
lines

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值