Python入门学习

  1.语法

  • 缩进来表示语句块
  • 注释:单行用#   多行用"""  注释内容  “”“ ,就是前后三个双引号。

  2.变量

  • 变量不需要声明,直接可以赋值。
  • 数字主要有  int 和float两种,可以通过 print( type(变量名) )  查看变量类型。
  • 强制转化用  int() float() str()
  • 字符串:用双引号或单引号引起来

            

    一些函数:len()  upper() lower() strip() split()

    

 

  3.部分 运算符

  /  Division 

  // Floor division  

  and 相当于C的  &&   

  or  相当于C的  ||

  not  相当于C的!

  还有特殊的属于运算符   in  和  not in

   4.测试LIST

  

  

  5.测试 元组tuple

  元组里的数据不能改变

  

   

   

   6.测试 集合SET(简单用一下)

  

   这个类还有很多功能,先不学了,按ctrl+set进入这个说明

   

   7.字典Dictionary 简单测试

  

   8.分支结构

  

   

   9.循环

  

  

  10.zip函数

  

  11.enumerate枚举函数

  

   

   12.效率比较(列表解析式不仅方便,效率也更高)

  

  13.FUNCTION

    

   14.案例

   实现单词个数的统计 

import  string
def main():
    file = r"C:\Users\Administrator.XTZJ-2020MNRXSY\Desktop\SCY\新建文本文档.txt"
    with open(file,'r') as text:
        words = [ raw_word.strip(string.punctuation).lower() for raw_word in text.read().split() ]
        print(words)
        words_index = set(words)
        count_dict = { index:words.count(index) for index in words_index }
    for word in sorted(count_dict,key= lambda x:count_dict[x],reverse = True):
        print( "{}--{} times".format(word,count_dict[word]) )

if __name__ == "__main__":
    main()

 

 

  15.作业

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洛阳八中我最棒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值