zoukankan      html  css  js  c++  java
  • Python小练习(持续更新....)

    最近一直在学习python,这些小练习有些是书上的,有些是别人博客上的!

    # 1.题目1
    # 给一个字符串,统计其中的数字、字母和其他类型字符的个数;
    # 比如输入“124mid-=”,输出:数字=3,字母=3,其他=2。

     1 #coding-utf8
     2 # 1.题目1
     3 # 给一个字符串,统计其中的数字、字母和其他类型字符的个数;
     4 # 比如输入“124mid-=”,输出:数字=3,字母=3,其他=2。
     5 
     6 #--------------------------------例子----------------------
     7 # s=input("请输入..")
     8 # print(s.isdigit())  # 用isdigit函数判断是否数字
     9 # print(s.isalpha())  # isalpha判断是否字母
    10 # print(not (s.isalpha() or s.isdigit()) and s.isalnum())  # isalnum判断是否数字和字母的组合
    11 
    12 #----------------------------------------end----------------------------
    13 
    14 #定义初始化变量
    15 strcount=0
    16 intcount=0
    17 othercount=0
    18 s=input("请输入..")
    19 for i in  s :
    20     if i.isdigit() :
    21         intcount+=1
    22     elif i.isalpha() :
    23         strcount+=1
    24     else:
    25         othercount+=1
    26 print("字母=%d,数字=%d,其他的=%d"%(strcount,intcount,othercount))

    题目2

    1 # 题目2:删除列表中重复的元素
    2 # 如果列表中有重复的元素,我们想要删除重复的
    3 li = [1, 2, 3, 4, 5, 2, 1, 3, 4, 57, 8, 8, 9]
    4 print(li)#打印下
    5 for x in  li :
    6      while li.count(x) > 1 :
    7          li.remove(x)
    8 
    9 print(li)

     方法很多,我比较懒,选择了最简单的一种方式!



  • 相关阅读:
    企业——Zabbix分布式服务监控平台添加监控服务(http、nginx、mysql)
    企业——Zabbix proxy分布式监控配置
    企业——Zabbix Agent Active 主动模式监控
    Linux背背背(4)vim操作
    Linux背背背(3)
    Linux背背背(2)
    如何防止远程提交?
    PHP常用的转义函数
    本博客点击页面,浮出文字的特效
    华硕R系列的解剖图
  • 原文地址:https://www.cnblogs.com/java-synchronized/p/6693333.html
Copyright © 2011-2022 走看看