Cov txheej txheem:

Python Txoj Kev Yooj Yim: 8 Kauj Ruam
Python Txoj Kev Yooj Yim: 8 Kauj Ruam

Video: Python Txoj Kev Yooj Yim: 8 Kauj Ruam

Video: Python Txoj Kev Yooj Yim: 8 Kauj Ruam
Video: Data Science with Python! Extracting Metadata from Images 2024, Kaum ib hlis
Anonim
Python Txoj Kev Yooj Yim
Python Txoj Kev Yooj Yim

Yog li koj tau txiav txim siab kawm yuav ua li cas Python thiab koj tau hla qhov kev qhia no. (Yog, Kuv tab tom siv Python ua lus qhia.)

Kuv paub koj yuav txhawj xeeb, tshwj xeeb tshaj yog tias qhov no yog koj thawj hom lus, yog li cia kuv tso siab rau koj …

Nab hab sej yog qhov siv tau yooj yim heev rau tus neeg siv lus programming uas tsis tsuas yog koj tuaj yeem kawm hauv ib teev, tab sis koj ib txwm twb paub nws, txij li nws tau nkag siab.

Ua ntej tshaj plaws, nws yog ib qho tseem ceeb kom paub tias cov programmer los ntawm tsis txhais tau tias paub ib hom lus programming li nws ua tau. Ntau txoj haujlwm yog paub txog yam koj xav ua, tsis paub yuav ua li cas thiab Googling cov lus teb, nrhiav tus lej piv txwv, tom qab ntawd hloov kho kom haum koj qhov xav tau.

Nab hab sej yog hom lus programming nrov, uas txhais tau tias cov lej piv txwv tuaj yeem pom hauv online.

Hauv cov lus qhia no peb yuav kawm paub yuav ua li cas Python nce thiab khiav, hla qee qhov piv txwv piv txwv piv txwv (nrog daim ntawv tsis ncaj nrog cov piv txwv zoo dua thaum kawg).

Muaj qhov txuas rau kuv GitHub, qhov twg txhua tus lej piv txwv tau tshaj tawm.

Txij li Instructables tuaj yeem cuam tshuam cov cai, Kuv pom zoo kom koj luam thiab muab cov piv txwv piv txwv los ntawm GitHub:

Kauj Ruam 1: Txhim Kho Python

Kuv paub, koj paub yuav ua li cas rub tawm thiab teeb tsa yam, duuuh.

Txawm li cas los teeb tsa Python yog qhov nyuaj me ntsis yog tias nws yog koj thawj zaug ua, tab sis qhov no yog vim li cas koj thiaj nyeem cov ntawv no ib qib zuj zus. Koj yuav nyob zoo.

-Click ntawm "Rub tawm Windows x86-64 executable installer" ntawm no:

(Kuv xav tias koj siv Windows, yog tias tsis yog, cov txheej txheem ntau dua lossis tsawg dua qub)

-Thaum rub tawm tiav, tsuas yog ntaus NEXT kom txog thaum nws teeb tsa. Kuv pom zoo hloov txoj kev teeb tsa rau qee yam tsis meej pem xws li "C:/Python"

Nrog koj zoo siab, koj nyob nraum ua tiav! Tam sim no koj tuaj yeem siv Python, txawm li cas los xij nws yog qhov zoo kom muaj qee cov pob khoom sib xws, uas peb yuav ua hauv cov kauj ruam tom ntej.

Kauj Ruam 2: Txhim Kho Pob

Txhim Kho Pob
Txhim Kho Pob
Txhim Kho Pob
Txhim Kho Pob

Yog tias koj xav tau, koj tuaj yeem hla cov kauj ruam no, txij li Python muaj peev xwm ua ntau yam khoom ncaj tawm ntawm lub thawv.

Txawm li cas los xij, koj yuav xav txheeb xyuas cov kauj ruam txij li thaum kawg koj yuav xav tau teeb tsa qee pob khoom thaum koj yuav xav ua ntau yam zoo nkauj nrog Python.

Yog tias koj yog tus kawm paub pom ntau dua, ntawm no yog daim vis dis aus yuav ua li cas:

Cov ntawv qhia:

Thaum Python kev teeb tsa ua tiav, mus rau daim nplaub tshev uas koj tau nruab Python (cia peb hais tias nws yog C:/Python) thiab nrhiav cov npe hu ua "Scripts". Hauv nws yuav tsum muaj cov ntaub ntawv npe "pip3.8" (lossis tus lej siab dua thaum kawg, nyob ntawm seb koj tab tom nyeem qhov no, yog li tsuas yog nrhiav pipX. Y)

-Tsis txhob nyem rau ntawm pip 3.8, peb tsis ua qhov ntawd (saib, tsis ncaj ncaj rau tom ntej zoo li nws yuav zoo li)

-Txawm yog tuav Ctrl, txoj cai nyem rau qee qhov hauv Scripts folder thiab nrhiav "Qhib PowerShell", nyem qhov ntawd. Ib qho screen xiav nrog qee cov ntawv ntawm nws yuav qhib.

-Thaum koj nyob ntawd, ntaus pip3.8 nruab numpy thiab ntaus nkag

Qhov ntawd yog nws, qhov no yog li cas koj teeb tsa lub tsev qiv ntawv! Yooj yim, huh?

Tam sim no, thaum koj tab tom txhim kho pob khoom, thaum txhim kho tus lej tsis tiav, koj yuav tsum tau teeb tsa matplotlib thiab scipy. Lub ntsiab lus hom "pip3.8 install NAME"

Thaum qhov ntawd ua tiav, koj txhua tus tau teeb tsa kom pib ua haujlwm.

Kauj Ruam 3: Thawj Python Program (Teeb)

Thawj Python Program (Teeb)
Thawj Python Program (Teeb)
Thawj Python Program (Teeb)
Thawj Python Program (Teeb)
Thawj Python Program (Teeb)
Thawj Python Program (Teeb)

Thaum peb teeb tsa Python, peb teeb tsa Python IDLE, thiab peb yuav siv nws los sau peb cov haujlwm nrog.

Tu siab nws tsis muaj lub cim ntxim hlub. Koj tuaj yeem pom nws hauv C: / Python / Python38 / Lib / idlelib hauv kuv qhov xwm txheej.

-Koj nyob hauv koj phau ntawv teev npe installatin mus rau Lib thiab tom qab ntawd mus rau idlelib. Nrhiav ib daim ntawv hu ua "idle" thiab khiav nws. Ib lub qhov rai yuav qhib.

-Nyem Ctrl+N qhib lub qhov rai tshiab lub npe "tsis muaj npe". Nov yog qhov uas peb yuav sau peb thawj qhov program Python!

-Tsuas yog tshuaj xyuas yog tias txhua yam ua haujlwm zoo li hauv qab no:

print ("Kuv tau ua txhua yam no")

-Hit F5 kom txuag tau cov ntawv. Xaiv lub npe thiab khaws nws nyob qhov twg koj yuav pom nws. Kuv pom zoo cov ntaub ntawv tshwj xeeb npe hu ua Python ntawm koj lub desktop.

-Thaum ntaus F5, koj yuav txuag ib qho kev hloov pauv thiab tseem ua haujlwm. Lub qhov rai tshiab yuav qhib thiab yuav sau "Kuv tau ua txhua yam no" sab hauv. Thiab koj tau ua txhua yam no, koj tau sau koj thawj Python program. Nrog koj zoo siab!

Kuv pom zoo kom koj tsim ib qho luv luv rau tsis ua haujlwm thiab muab tso rau ntawm koj lub Desktop kom nkag tau yooj yim rau yav tom ntej.

Hauv cov theem hauv qab no kuv yuav piav qhia qhov tseem ceeb ntawm kev ua haujlwm li cas hauv Python. Xav tias dawb los tshuaj xyuas lawv yog tias koj tshiab rau lub cajmeem lossis hla mus rau kauj ruam kawg uas kuv tau txuas nrog Python dag-daim ntawv nrog rau feem ntau ntawm cov yam ntxwv hauv cov qauv piv txwv.

Kauj ruam 4: Cov lus pom

Txij li peb twb paub yuav ua li cas luam aka sau cov khoom ntawm lub vijtsam, peb tuaj yeem txav mus rau ntxiv cov lus rau peb tus lej. Cov lus pom yog ib feem tseem ceeb heev ntawm kev sau thiab ua rau koj zoo li tus kws tshaj lij. Cov lus pom yog kab ntawm cov cai uas tsuas yog rau cov neeg nyeem cov cai. Lawv piav qhia qhov seem ntawm cov cai yuav tsum ua li cas hauv tib neeg cov lus, yog li koj tsis tas yuav tshuaj xyuas txhua kab ntawm cov cai tsuas yog pom nws ua dab tsi.

Nco ntsoov, lus pom zoo = zoo

Peb sau cov lus pom los ntawm kev siv #. Python tsis pom dab tsi tom qab #, cov lus pom zoo li no:

print ("Kuv tau ua nws dua") #Oops

Yog tias koj ntaus F5 thiab khiav qhov program, cov ntawv tso tawm yuav yog "Kuv tau ua nws dua" yam tsis muaj Oops.

Tam sim no koj paub yuav tawm tswv yim koj cov cai li cas, cia peb txav mus rau qee qhov kev suav.

Cov lus qhia muaj peev xwm cuam tshuam cov cai yog tias koj theej thiab muab nws tso rau hauv, yog li kuv pom zoo koj luam cov cai rau theem no los ntawm kuv GitHub, ntawm no.

Kauj Ruam 5: Txuag thiab Ua Haujlwm Nrog Cov Qub

Txij li thaum peb sau cov haujlwm tam sim no, feem ntau ntawm lawv yuav tsum khaws cov ntaub ntawv uas peb sau rau hauv qhov program thiab tom qab ntawd ua qee yam nrog nws. Koj tuaj yeem ua tus lej cov ntaub ntawv rau hauv qhov haujlwm ua ntej nws ua haujlwm lossis nkag nws thaum hais los ntawm kev siv lub luag haujlwm ua haujlwm ().

Ua ntej koj yuav tsum paub tias Python (thiab lwm yam lus programming) tsis pom = zoo li peb ua.

Txog Python = txhais tau tias txuag sab xis ntawm = mus rau sab laug ntawm =. Txhawm rau zam kev tsis meej pem, cia saib ib qho piv txwv.

Raws li peb tam sim no yog tus tsim qauv, piav qhia txog cov cai yuav ua li cas hauv cov lus.

a = 1 #lub npe tam sim no sib npaug 1

b = a #since sib npaug 1, b tam sim no kuj sib npaug 1

print ("a") #peb yuav tsum luam tawm qhov txiaj ntsig txhawm rau pom qhov haujlwm ua haujlwm

Raws li koj yuav tau pom, cov haujlwm hauv Python ua los ntawm thawj kab mus rau qhov kawg hauv kev ua ntu zus. Qhov no txhais tau tias yog tam sim no peb rov txheeb xyuas qhov sib txawv, tus nqi hauv nws yuav raug hloov pauv. Piv txwv li:

a = 1 #a yog 1b = a #b kuj yog 1, txij li a = 1a = 2 #a tam sim no tau hloov mus rau 2, tab sis b tseem nco tau thawj tus nqi ntawm a, vim peb tau hloov tus nqi ntawm a hauv kab 3 thiab b tau txhais ntawm kab 2

print ("ib")

luam tawm ("b")

Cov lus qhia muaj peev xwm cuam tshuam rau cov cai yog tias koj theej thiab muab tso rau nws yog li kuv pom zoo koj luam cov cai rau theem no los ntawm kuv GitHub, ntawm no.

Kauj Ruam 6: Kev suav

Tam sim no cia ua qee qhov kev suav, tsuas yog hloov kho me me los ntawm qhov peb tau ua hauv qib dhau los.

ib = 1

b = 2 hli

c = 0 #first peb muab c tus nqi, yog li vim li cas tsis 0, nws tuaj yeem yog txhua yam txawm hais tias, txij li peb yuav hloov tus nqi hauv kab tom ntej

c = a+b #c tam sim no 1+2 aka c = 3

print ("c:", c) #we print "c:" raws li ntawv, tom qab ntawv ntxiv tus c kom nws zoo li zoo nkauj

print ("a:", a, "b:", b, "c:", c) #zoo ib yam li peb luam tawm lwm qhov kev hloov pauv thiab lawv lub npe

Ntau yam tib yam peb tuaj yeem siv:

+, - ntxiv thiab rho tawm yog tus kheej piav qhia

* multiplies tus nqi

/ faib qhov tseem ceeb

Piv txwv li:

ua = 1

b = 2 hli

c = a/b #tus nqi c yog tam sim no 1/2 aka 0.5

sau ("c:", c)

Cov lus qhia muaj peev xwm cuam tshuam cov cai yog tias koj theej thiab muab nws tso rau hauv, yog li kuv pom zoo koj luam cov cai rau theem no los ntawm kuv GitHub, ntawm no.

Kauj Ruam 7: Yog Cov Lus Hais

Qee zaum peb yuav xav kom peb txoj haujlwm luam tawm qee qhov txiaj ntsig tsuas yog YOG muaj qee yam tshwm sim. Hauv qhov haujlwm no, peb tsuas yog sau tus lej yog tias nws siab dua 100:

tus naj npawb 1 = 10 #peb tuaj yeem muab nws lub npe, cov piv txwv yav dhau los siv ua piv txwv

mississippi = 90 #pom, lub npe tuaj yeem yog txhua yam, tsuav nws pib nrog tsab ntawv

a = 91 #peb tseem tuaj yeem siv a

yog tus lej 1+mississippi> = 100: #IF sab laug loj dua lossis sib npaug rau sab xis

print ("number1+mississippi yog tsawg kawg 100") #ua qhov no (yog, nws yuav tsum tau nkag mus)

yog tus naj npawb 1+a == 100: #IF sab laug yog raws nraim li txoj cai

print ("number1+a yog tsawg kawg 100") #ua qhov no, tshwj tsis yog IF yog qhov tseeb

Yog tias peb ua txoj haujlwm no, peb yuav pom tias nws tsuas yog luam tawm thawj nqe lus, txij li 10+90 yog 100

Cov lus qhia muaj peev xwm cuam tshuam rau cov cai yog tias koj theej thiab muab tso rau nws yog li kuv pom zoo koj luam cov cai rau theem no los ntawm kuv GitHub, ntawm no.

Kauj Ruam 8: Xaus ???

Puas yog txhua yam no yog Python ?!

Naaah, nyob deb ntawm nws. Tam sim no koj paub cov hauv paus ntawm yuav ua li cas txuag cov lej sib txawv thiab ua lej nrog lawv. Rau kev ua haujlwm tau zoo dua Kuv tau txuas nrog Python cheatsheet nrog cov qauv piv txwv yooj yim. Txoj hauv kev zoo tshaj los kawm yog sim ua piv txwv rau koj tus kheej thiab saib yuav muaj dab tsi tshwm sim thaum koj hloov txoj cai.

Cov ntaub ntawv tseem tuaj yeem pom ntawm kuv GitHub, ntawm no:

Pom zoo: