编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

新手怎么自学python,大概要多久?

wxchong 2024-09-12 21:56:57 开源技术 8 ℃ 0 评论

学编程语言有个小秘诀,直接上项目就是干,做完后你就是pythoner了。

不要怕没有基础,边做边查边学,进步很快的。

因人而异,一周或者一个月就能搞定。当然需要足够的投入。


以前我也觉得收集资料、啃语法、敲代码是学python的套路,但这样学效率太低。

你要知道python是一门脚本语言,不需要传统的编写-编译-链接-运行过程,语法简答、执行方便。

也就是说python像是个瑞士军刀,可以写出很多有用的小工具,随写随用。

下面介绍适合新手的python小项目:

贪吃蛇小游戏

用100行python代码写个贪吃蛇小游戏,也不复杂但涵盖了大部分python语法。

项目地址:https://gitee.com/codetimer/Snake/blob/master/main.py

可以尝试着先复制代码运行一遍,然后自己写。

人脸识别

调用开源项目,只需要简单的几十行python代码,就可以实现人脸识别。

项目地址:https://github.com/ageitgey/face_recognition

中文分词&情感分析

这个也比较有意思,可以爬取电商评论数据,然后分词处理,并做情感分析,判断好评、差评。

jieba可以用来做分词处理

https://github.com/fxsjy/jieba

snownlp可以用来做情感分析。

import snownlp
sentense = '''亲,第一天秒杀买,比第二天的正常价还高,
说保价7天申请售后说退差价也比不退,你们还有信誉吗
            '''
result = snownlp.SnowNLP(sentense)
a = result.words  # list
b = result.sentiments  # float
print("%.2f" % b)

https://github.com/isnowfy/snownlp

车型识别

这里使用python调用百度的车型识别模型,只要导入车辆图片可以自动识别车型。

import requests
import base64
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

# 输入你的api_key和secret_key,获取地址https://console.bce.baidu.com/ai
api_key = ''
secret_key = ''
url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + str(api_key) + '&client_secret=' + str(secret_key)
res = requests.get(url).text
a = eval(res)
access_token = a['access_token']
animal = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/car?access_token=' + str(access_token)
header = {
    'Content-Type':'application/x-www-form-urlencoded'
}
data = {}
with open('timg.jpg', 'rb') as f:
    image = base64.b64encode(f.read())
    data["image"] = str(image, 'utf-8')
    res2 = requests.post(url=animal,data=data, headers=header).text
    print('颜色:',eval(res2)['color_result'])
    print('车型预测')
    for each in eval(res2)['result']:
        print(each['name'], '\t相似度:', each['score'])
    plt.imshow(mpimg.imread(f))
plt.show()

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表