Python 1行代码系列

想到什么写什么:

①常用于acm题目中输入一个n值,并且进行n次循环的过程

for _ in range(int(input())):

②输入一个二维数组。

slist=[[input(),float(input())]for _ in range(n)]

san :输入str,将大写转换为小写,小写转换为大写

print ''.join([i.lower() if i.isupper() else i.upper() for i in raw_input()])

Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。

str = "-"; seq = ("a", "b", "c"); # 字符串序列

print str.join( seq );

输出结果a-b-c


④:%  和%s的输出时的用法

print (("Hello %s %s! You just delved into python.") % (first_name, last_name))

"%s" says that a string should be inserted in that position instead of the characters. Since there are 2 of them we need to add two strings into it.

the "%" says that the things after this are the strings we wanna replace with.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值