栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 小目标7

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 小目标7

Today we will try to work with Python Strings

Task1:Python has built-in string validation methods for basic data. It can check if a string is composed of alphabetical characters, alphanumeric characters, digits, etc
Hint Function: isalnum(), isalpha(), isdigit(), islower(), isupper()

Task2:You are given a string and width . Your task is to wrap the string into a paragraph of width

Example:

String :ABCDEFGH, Max_width= 4

Output: ABCD
EFGH

Solution: Task 1
    s = input()

    #alphanumerical characters
    print (any(i.isalnum() for i in s))

    #alpha
    print( any(i.isalpha() for i in s))

    #numerical
    print( any(i.isdigit() for i in s))

    #lowercase
    print( any (i.islower() for i in s))

    #uppercase
    print ( any(i.isupper() for i in s))

#Note we need (any x for i in s)
Task 2
def wrap(string, max_width):
    return(“n”.join([string[i:i+max_width] 
    for i in range(0, len(string), max_width)]))

Reference:
https://www.hackerrank.com

Originally published at fangya18.com on March 16, 2019.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/220863.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号