每日codingame小游戏练习[2021.3.27](python3入门学习之字母大小写判断)

题目描述

Given a line of alphabetic characters , extract all the uppercase characters to print them on the first line . Then extract all the lowercase characters to print them on the second.
Example:

inputouput
ABCDefghIJKLmnopABCDJKL
efghmnop

题目分析

题目大意
题目要求我们把输入的字符串大小写分开输出。

解题代码

我写的:

t=input()
list1=list(t)
list2=[]
list3=[]
for s in list1:
    if 'a'<=s<='z':
        list2+=s
    elif 'A'<=s<='Z':
        list3+=s
s1,s2,s3,s4='','','',''
for s1 in list2:
    s3+=s1
for s2 in list3:
    s4+=s1
print(s3)
print(s4)

大佬写的:

a=input()
str=''
print(str.join(i for i in a if 'a' <=i<='z'))
print(str.join(i for i in a if 'A' <=i<='Z'))

总结

  1. python中将一行代码放在for循环那行
  2. Python 用一行代码实现for循环初始化数组
  3. Python join()方法:jion方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
  4. 我真是太逊了!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值