久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      Python程序有有許多有助于高效編程的模塊和第三方包,了解這些模塊的正確使用方法是很重要的,下面本篇文章就來給大家總結(jié)分享10個(gè)有趣且實(shí)用的Python模塊,一起看看他們的功能吧!

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      閑話少說,我們直接開始吧。 :)

      1.Python偽信息生成器

      創(chuàng)建一個(gè)程序,生成虛假數(shù)據(jù),如姓名、電子郵件或包含個(gè)人所有信息的詳細(xì)虛假個(gè)人資料。

      Faker是一個(gè)python軟件包,可以在終端中使用pip install Faker安裝。每次運(yùn)行以下程序faker generator時(shí),都將產(chǎn)生不同的隨機(jī)數(shù)據(jù)。

      from faker import Faker fake = Faker() print(fake.name()) print(fake.email()) print(fake.country()) print(fake.profile())

      輸出如下:

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      2.手寫文本圖像

      實(shí)現(xiàn)一個(gè)程序?qū)⒔o定文本轉(zhuǎn)換為手寫筆記形式

      為了完成上述功能,需要第三方程序包pywhatkit,可以使用pip install pywhatkit進(jìn)行安裝。這個(gè)軟件包有很多其他功能,比如在谷歌上搜索等。

      樣例代碼如下:

      import pywhatkit pywhatkit.text_to_handwriting('''Learning Python from the basics is extremely important. Before starting to learn python,understanding a base language like c is a must and some of the oops concepts.Python program has many modulesand packages, which helps with efficient programming. Understanding these modules and 1proper usage of many syntax and libraries is recommended. In this article, a few modules and packages are used in the program.  Python includes tons of libraries and some of them are quiet intresting''')

      輸出如下:

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!
      輸出以圖像文件形式保存在當(dāng)前python文件目錄下。

      3.實(shí)現(xiàn)電腦關(guān)機(jī)

      實(shí)現(xiàn)一個(gè)程序來將電腦自動(dòng)關(guān)機(jī)

      實(shí)現(xiàn)上述功能需要用到OS庫,可以使用pip install os進(jìn)行安裝。我們可以使用該庫來實(shí)現(xiàn)關(guān)閉,重啟,或者設(shè)置關(guān)閉重啟倒計(jì)時(shí)等功能。
      樣例代碼如下:

      import os shutdown = input("Do you want to shutdown your computer (yes / no): ") if shutdown == 'yes':     os.system("shutdown /s /t 1") else:     print('Shutdown is not requested')

      注意事項(xiàng)如下:

      執(zhí)行此程序之前,請(qǐng)確保保存并關(guān)閉所有文檔。運(yùn)行此程序會(huì)導(dǎo)致計(jì)算機(jī)關(guān)閉后,未保存的數(shù)據(jù)可能會(huì)丟失。

      4.打印日歷

      實(shí)現(xiàn)打印指定月份和年份日歷的程序

      Python中有一個(gè)內(nèi)置模塊calendar,它可以幫助訪問日歷。在這個(gè)模塊中有很多方法,在下述程序中,我們?cè)噲D打印一年中指定月份的日歷。

      import calendar year =int( input("Enter the year of the required calendar ")) month = int( input("Enter the month of the required calendar ")) print(calendar.month(year,month))

      運(yùn)行結(jié)果如下:

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      5.畫一個(gè)餅圖

      實(shí)現(xiàn)在餅圖中用百分比表示每月費(fèi)用的程序

      在下述程序中,我們使用matplotlib來畫餅圖。可以使用pip install matplotlib安裝此庫。有了這個(gè)模塊,可以用python編寫許多交互式視覺效果。
      樣例代碼如下:

      import matplotlib.pyplot as plt Partition = 'Holidays', 'Eating_Out', 'Shopping', 'Groceries' sizes = [250, 100, 300, 200] fig1, ax1 = plt.subplots() ax1.pie(sizes, labels=Partition, autopct='%1.1f%%', shadow=True, startangle=90)          ax1.axis('equal') plt.show()

      運(yùn)行結(jié)果如下:
      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      6.彈出告警框

      實(shí)現(xiàn)一個(gè)程序來顯示帶有消息的告警框效果

      下述程序使用第三方庫pyautogui 來顯示告警框。通常來說,可以使用pip install pyautogui來安裝它。這個(gè)模塊有很多方法,比如使用python程序來控制鼠標(biāo)和鍵盤。
      樣例代碼如下:

      import pyautogui num=int(input("Enter a value to divide 100")) if num == 0:     pyautogui.alert(" Alert!!! 100 cannot be divided by 0") else:     print(f'The value is {100/num}')

      輸出如下:

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      7.文本轉(zhuǎn)語音

      實(shí)現(xiàn)一個(gè)程序來將文本轉(zhuǎn)化為語音

      為了實(shí)現(xiàn)將文本轉(zhuǎn)化為音頻,需要使用pip install pyttsx3 來安裝一個(gè)轉(zhuǎn)換庫。這個(gè)庫有很多模塊,我們還可以嘗試改變音頻的聲音、音量和速度。
      樣例代碼如下:

      import pyttsx3 engine = pyttsx3.init() engine.say('This is a python example in MEDIUM') engine.runAndWait()

      上述代碼運(yùn)行后,輸出是一個(gè)女性聲音,將對(duì)應(yīng)的文字轉(zhuǎn)化為音頻播放。

      8.截圖

      實(shí)現(xiàn)一個(gè)python程序,來實(shí)現(xiàn)截取屏幕截圖的功能

      如下代碼所示,我們使用python庫pyautogui 來實(shí)現(xiàn)截屏功能。代碼如下:

      import pyautogui screenshot = pyautogui.screenshot() screenshot.save("screenshot.png")

      上述代碼運(yùn)行后,輸出文件截圖保存在 python 源文件目錄下。我們可以嘗試使用 time.sleep() 語法來延遲屏幕截圖。

      9.網(wǎng)絡(luò)監(jiān)測(cè)

      實(shí)現(xiàn)一個(gè)python程序,用來檢測(cè)互聯(lián)網(wǎng)上傳和下載速度

      在下述程序中,為了監(jiān)測(cè)互聯(lián)網(wǎng)速度,我們使用了speedtest 庫,要安裝此第三方庫,可以使用 pip install speedtest-cli 語法進(jìn)行安裝。

      代碼如下:

      import speedtest speed = speedtest.Speedtest() download_speed = speed.download() upload_speed = speed.upload() print(f'The download speed is {download_speed}') print(f'The uplaod speed is {upload_speed}')

      運(yùn)行結(jié)果如下:

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      10.用 Python 繪制圖形

      實(shí)現(xiàn)一個(gè)程序,使用turtle 制作螺旋圖形

      在下述程序中,我們使用 Python中的Turtle 繪制了一個(gè)螺旋圖。要安裝該庫,可以使用pip install PythonTurtlePython Turtle主要用于繪制視覺圖形,以及圖形的形狀顏色設(shè)置。
      樣例代碼如下:

      import random import turtle colors = ['red','cyan','pink' ,'yellow', 'green','orange'] t = turtle.Turtle() t.speed(10) turtle.bgcolor("black") length=100 angle =50 size=5 for i in range(length):     color=random.choice(colors)     t.pencolor(color)     t.fillcolor(color)     t.penup()     t.forward(i+50)     t.pendown()     t.left(angle)     t.begin_fill()     t.circle(size)     t.end_fill() turtle.exitonclick() turtle.bgcolor("black")

      運(yùn)行結(jié)果如下:

      分享10個(gè)有趣且實(shí)用的Python模塊,看看他們的功能吧!

      總結(jié)

      本文重點(diǎn)匯總了使用Python中的第三方庫來實(shí)現(xiàn)常見場(chǎng)景下的一些簡單有趣的功能,并給出了樣例程序和相應(yīng)的解釋。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)