python字符串与列表

字符串是一个不可修改的序列

# 每次循环只向列表添加字符串,没有创建列表对象
# 要求最后的结果为012345678,将列表转换为字符串
list_tmp =[]
for item in range(10):
    list_tmp.append(str(item))
# join:将列表转为字符串
result = "".join(list_tmp)#result = "连接符".join(列表)
print(result)
list_01 =[]
while True:
    str_input = input("请输入内容:")
    if str_input == "":
        break
    list_01.append(str_input)
result = "".join(list_01)
print(result)
"""
str -->list
"""
str01 = "张无忌-赵敏-周芷若"
list_result = str01.split("-")
print(list_result)
str01 = "张无忌-赵敏-周芷若"
list_result = str01.split("-")#用“-”符号对字符串进行分割成一个列表
print(list_result)
str_01 = "How are you"
str_list = str_01.split(" ")
#str_list.reverse()
result = " ".join(str_list[::-1])
print(result)
list_01 = [1, 2, 8, 9, 6, 10, 18, 59]
min_num = list_01[0]
for item in range(1, len(list_01)):
    if item < min_num:
        min_num = item
print(min_num)
import random

list_01 = []

while len(list_01) < 6:

    red_ball = random.randint(1, 33)
    if red_ball not in list_01:
        list_01.append(red_ball)
blue_ball = random.randint(1, 16)
list_01.append(blue_ball)
print(list_01)
list_01 = []

while len(list_01) < 6:


    red_ball = int(input("请输入第%d个红球号码:" % (len(list_01)+1)))

    if 1 > red_ball or red_ball > 33:
        print("号码不在范围内")
    elif red_ball in list_01:

        print("号码已经重复")
    else:

        list_01.append(red_ball)

while len(list_01) < 7:
    blue_ball = int(input("请输入篮球号码"))
    if 1 > blue_ball or blue_ball > 16:
        print("号码不在范围呀")

    else:
        list_01.append(blue_ball)
print(list_01)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值