python笔记

#python笔记
l = input().split(' ')   #一个变量接收多个值,自动保存为列表型
m=str(l)
print("{} {}".format(type(l),l))
print("{} {}".format(type(m),m))
#可以把list类型转为str型


n, a=input().split(' ')
print("{} {}".format(type(n),n))
print("{} {}".format(type(a),a))
#用input()每次输入一个变量,默认保存为字符串型


l=list(input().split(' '))
print(l)
#输出:['python', 'is', 'good']
-----------------------------
l=[]
l.append(input().split(' '))
print(l)
#输出:[['python', 'is', 'good']]


def rep(l):
    m=[]
    for i in l:
        m.append(i.replace("n","N"))   #replace是字符(串)内置方法
    return m
l=[]
n=eval(input())
for i in range(n):
    l.append(input())
print(l)
#append方法将输入作为字符加入到列表中
ls=l.copy()         #copy复制不是映射复制,对copy来的列表的处理不会影响到原列表
print("{} {}".format(l,ls))
m=rep(ls)
print("{} {}".format(l,m))
for i in l:
    i=i.replace("n","N")
    print("{} ".format(i),end='')
#输出:pythoN project veNy scripts maiN
#replace方法转换元素必须有值来接收才会最终表示出来

#用 try-except处理多行输入模板:
try:
    l=[]
    while(True):
        l.append(input())
except:
    pass

#在同一行以空格为分隔输入两个数
n, a=input().split(' ')
n=int(n)   #强制类型转换必须有元素接收

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Anndy.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值