Python基础总结(4)

元组:戴上枷锁的列表

tuple1=(1,2,3,4,5,6,7,8)

更新元素方法

temp=('aaa','vvv','ccc','ddd')
temp=temp[:2]+('hehe',)+temp[2:]
print "{0}.{1}.{2}".format("www","superkingdom","cn")
print "{a}.{b}.{c}".format(a="www",b="superkingdom",c="cn")
print '%c' %(97)
print '%s' %('cjfsdl')
print '%d' %(4)

max(tuple1)取最大值
sum(tuple1)求和
sorted(numbers)
reversed(numbers)
enumerate(numbers)枚举
zip(a,b)
a=[1,2,3,4,5,6,7,8]
b=[4,5,6,7,8]
zip(a,b)
[(1,4),(2,5),(3,6),(4,7),(5,8)]

函数与过程
Python只有函数

def discounts(price,rate):
    final_price=price*rate
    return final_price
old_price=float(input('请输入原价:'))
rate=float(input('请输入折扣率:'))
new_price=discounts(old_price,rate)
print('折后价是:',new_price)

filter()过滤器
filter(function or None,iterable)

print list(filter(lambda x:x%2,range(10)))

map()加工 将序列加工之后返回

print list(map(lambda x:x*2,range(10)))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值