Cov txheej txheem:

Pib Nrog Python: 7 Kauj Ruam (nrog Duab)
Pib Nrog Python: 7 Kauj Ruam (nrog Duab)

Video: Pib Nrog Python: 7 Kauj Ruam (nrog Duab)

Video: Pib Nrog Python: 7 Kauj Ruam (nrog Duab)
Video: Finance with Python! Net Present Value (NPV) 2024, Kaum ib hlis
Anonim
Pib Nrog Python
Pib Nrog Python

Programming yog txaus!

Nws muaj tswv yim, nws lom zem thiab nws muab koj lub hlwb ua haujlwm rau lub hlwb. Coob leej ntawm peb xav kawm txog kev ua haujlwm tab sis ntseeg peb tus kheej tias peb ua tsis tau. Tej zaum nws muaj lej ntau dhau, tej zaum cov lus uas cuam tshuam ib puag ncig ua rau koj ntshai. Cia kuv qhia koj tam sim no uas yog qhov uas cov programmer tau xav ua ntej lawv dhau los ua programmer. Qhov tseeb qhov ntawd yog qhov kuv tab tom tsawg dua 10 lub lis piam dhau los thaum kuv pib ua haujlwm.

Cia kuv qhia koj tam sim no tias leej twg tuaj yeem kawm sau cov program. Nrog kev nce qib hauv kev yooj yim nyeem cov lus lus zoo li nab nab, thiab cov ntaub ntawv muaj txiaj ntsig hauv is taws nem, Nws tsis yog peev txheej puv sijhawm los kawm cov lus thiab tawm ntawm cov lus programming. Me nyuam mos feem ntau '21st caug xyoo' cov kws tsim tawm tub nkeeg heev, tsuas yog kawm cov hauv paus thiab tsim los ntawm qhov ntawd.

Nov yog No-Jargon, yooj yim ua raws ible uas koj tuaj yeem ua tam sim no. Yog lawm! Tsawg facebook thiab youtube, so thiab ua raws koj lub computer.

Tus Neeg Laus Computer
Tus Neeg Laus Computer

Hnub no peb yuav saib cov lus programming hu ua Python, wikipedia txhais cov nab nab raws li:

"Python yog siv dav dav-lub hom phiaj, qib lus programming. Nws tsim lub tswv yim hais txog kev nyeem tau yooj yim, thiab nws cov syntax tso cai rau cov programmer los nthuav qhia cov ntsiab lus hauv kab tsawg ntawm cov cai ntau dua li ua tau hauv cov lus xws li C ++ lossis Java. muab cov phiaj xwm tsim los pab kom muaj kev qhia meej ntawm ob qho me me thiab loj."

Yog li dab tsi nws txhais tau tias? Kuv xav tias koj hais tias tsis yog-jargon? Zoo hauv paus:

"Python yog kev cog lus, lub hom phiaj dav, yooj yim nyeem cov lus programming. Nws muaj ntau yam, yog li tuaj yeem siv los tsim cov phiaj xwm ntawm txhua qhov loj me."

Vim li cas kuv thiaj xaiv nab nab? Vim tias cov hauv paus ntawm nab nab yog qhov yooj yim mus nqa thiab cov lus muaj kev txhawb nqa zoo hauv zej zog online. Tom qab ua tiav ible no koj tuaj yeem pib ua cov haujlwm tam sim, tsis txhob siv koj lub sijhawm los kawm qhov xav tau ntawm cov lus.

Yog li cia pib!

Kauj ruam 1: Yam Koj Yuav Tsum Tau

Ua ntej koj yuav xav tau lub khoos phis tawj nrog daim ntawv nab npawb nab, thov txim cov neeg siv mobile!

Lub taub hau mus rau https://www.python.org/downloads/ thiab rub tawm qhov tseeb tshaj tawm muaj nrog khawm daj loj.

Nab hab sej download
Nab hab sej download

Tom qab ntawd ua raws li Cov Lus Qhia Qhia rau nruab nab nab.

Nab hab sej Installer
Nab hab sej Installer

Txhawm rau txheeb xyuas tus nab npawb raug teeb tsa, mus rau CMD (lossis davhlau ya nyob twg) thiab ntaus:

nab hab sej --version

Nab hab sej yuav tsum teb nrog cov lus ntawm nab nab.

Duab
Duab

Tam sim no rau qhov kev qhia no peb yuav siv IDE, lossis Kev Txhim Kho Ib Leeg Ib puag ncig (feem ntau yog cov ntawv sau thiab sau ua ke ua ke) yog li taub hau mus rau https://www.jetbrains.com/pycharm/download/ thiab rub tawm "Community Edition" ntawm Pycharm.

PyCharm Zej Zog
PyCharm Zej Zog

Tom qab ntawd ua raws li Cov Lus Qhia Txhawm rau nruab PyCharm.

Tam sim no, los pib lub programming!

Kauj Ruam 2: Teeb PyCharm thiab Tsim Txoj Haujlwm Tshiab

Thawj zaug koj tso pycharm nws yuav nug koj tias tus lej tseem ceeb thiab lub ntsiab lus twg koj xav siv. Kuv xav rov qab tawm hauv daim ntawv qhia tseem ceeb ntawm lub neej ntawd, tab sis koj tuaj yeem ua si ib puag ncig nrog lub ntsiab lus, xim thiab fonts rau koj nyiam. Txog qhov kev qhia no kuv siv pycharm zej zog 4.5 nrog Dracula ntsiab lus.

Tom qab ntawd koj yuav tau txais tos nrog lub vijtsam txais tos.

Nias Tsim Txoj Haujlwm Tshiab

PyCharm Zoo Siab Txais Tos
PyCharm Zoo Siab Txais Tos

Xaiv Ntshiab Python ces xaiv daim nplaub tshev khaws cov ntaub ntawv hauv, tom qab ntawd nyem tsim (Nco ntsoov tias lub npe nplaub tshev yuav yog lub npe ntawm koj txoj haujlwm)

PyCharm Project Screen
PyCharm Project Screen

Txij ntawm no mus koj yuav tsum tau txais tos nrog qhov Code Tsim Screen: P

Code Screen
Code Screen

Kauj Ruam 3: Tsim Koj Thawj Txoj Haujlwm

Txoj Cai Nyem rau ntawm koj cov ntawv tais ceev tseg thiab mus rau tshiab -> Cov Ntaub Ntawv Python

Tsim MENU tshiab
Tsim MENU tshiab

Npe cov ntaub ntawv thiab nias ok

Cov Ntaub Ntawv Sib Tham
Cov Ntaub Ntawv Sib Tham

Tam sim no lub tab tshiab yuav tshwm sim hauv koj cheeb tsam tseem ceeb

Duab
Duab

Hauv qab no _author_ theej thiab muab cov cai no tso.

lus = "Nyob zoo ntiaj teb"

sau lus

Tom qab ntawv nyem rau ntawm daim ntawv thiab nias Khiav

Duab
Duab

Qhov no yuav suav peb qhov program thiab xa rov qab los. Nyob Zoo Lub Ntiaj Teb yuav luam tawm hauv Qhov Chaw Khiav

Duab
Duab

Cia peb saib qhov peb nyuam qhuav sau.

Kauj Ruam 4: Txheeb Tawm Koj Thawj Txoj Haujlwm

Tam sim no cia sim nkag siab qhov chaws

lus = "Nyob zoo ntiaj teb"

sau lus

tiag tiag txhais tau tias.

Ua ntej kuv tsim thiab teeb tus nqi ntawm qhov sib txawv rau txoj hlua uas muaj Nyob Zoo Lub Ntiaj Teb, Yog tias koj hloov cov ntawv ntawm cov lus hais lus ces koj tuaj yeem hloov tus nqi ntawm qhov sib txawv thiab yog li ntawv. Rau qhov xwm txheej:

lus = "Nyob Zoo Cov Lus Qhia!"

sau lus

Rov qab los:

Duab
Duab

thaum khiav.

Txoj hlua tau hais tseg vim yog cov cim hais lus, cov hlua kuj tuaj yeem txhais nrog cov cim ib leeg

lus = 'Nyob zoo ntiaj teb'

sau lus

Variables tseem tuaj yeem muaj ntau hom sib txawv. Rau qhov xwm txheej no:

cov = 29302

yog qhov sib txawv nrog tus lej integer (sau luv int) thiab qhov no:

floatingPoint = 1469.928

yog qhov sib txawv nrog tus nqi taw tes ntab (sau luv rau ntab).

Yeej, qhov sib txawv ntawm cov lej thiab cov ntab yog cov lej suav tag nrho thaum ntab yog cov lej lej. Cov zauv siv chav tsawg dua tab sis tsis tuaj yeem tuav cov zauv zauv. Piv txwv li interger 1 / integer 2

integer1 = 1

integer2 = 2 luam integer1 / integer2

yog 0.5 txoj cai? Tab sis qhov tshwm sim yog:

Duab
Duab

Vim tias cov lej tsis tuaj yeem faib ua cov zauv. Txawm li cas los qhov no:

float1 = 1.0

integer2 = 2 luam float1 / integer2

rov qab 0.5 thaum khiav vim tias ib qho ntawm qhov sib txawv yog ntab

Duab
Duab

'Luam tawm' yooj yim luam tawm tus nqi. Rau Instance

sau "DESTROY THE WORLD"

luam tawm txoj hlua

Duab
Duab

Luam kuj tuaj yeem luam tus nqi ntawm ib qho zauv, suav nrog ob txoj hlua sib txuas

string1 = "HLO"

string2 = "IBLE LOVERS" luam tawm string1 + string2

luam tawm

Duab
Duab

Kauj Ruam 5: Loops thiab Yog Yog - Tswj Cov Qauv

Ib qho tseem ceeb tshaj plaws ntawm ib qho haujlwm twg yog qhov muaj kev tswj hwm cov qauv.

Thawj qhov kev tswj hwm yog lub sijhawm voj, daim ntawv ntawm cov lej loops thaum qhov xwm txheej muaj tseeb. Rau qhov xwm txheej no

suav = 0

thaum suav <10: # Ntxiv rau suav suav = suav + suav 1 suav suav sau "Ua tiav"

sau cov cai hauv lub voj kom txog thaum suav <10 thiab tom qab ntawd txuas ntxiv nrog qhov program.

Duab
Duab

Qhov thib ob yog cov lus hais yog-lwm qhov, daim ntawv no kuaj xyuas thiab ua qee yam yog tias tus nqi sib txawv sib npaug li 10, ua lwm yam yog tias tus nqi sib npaug 11 thiab ua lwm yam hauv txhua qhov xwm txheej.

integer = 0

# Yog nws sib npaug rau 10 yog integer == 10: print "ITS 10" # Yog tias nws sib npaug rau 11 elif integer == 11: print "ITS 11" # Hauv txhua lwm qhov xwm txheej ntxiv: luam tawm "Kuv DONT KNOWWWWWWWWW" print "Tiav lawm"

Yuav rov qab los

Duab
Duab

Vim tias qhov sib txawv ntawm qhov sib npaug tsis sib npaug rau 10 lossis 11 thiab hauv txhua qhov xwm txheej nws khiav lwm qhov.

Txhawm rau txheeb xyuas ib ntus lossis yog tias tus qauv tswj hwm muab hom (thaum lossis yog) ua raws tus nqi tseeb lossis cuav ces:

hom tseeb == muaj tseeb:

Daim ntawv ceeb toom tus 'whitespace' rau cov ntsiab lus ntawm txhua lub voj, nab nab tshwj xeeb heev txog qhov chaw dawb, qhov ntawd yog li cas nws thiaj paub tias tus lej nyob hauv ib pliag lossis yog lub voj. PyCharm siv ib lub tab dawb qhov chaw uas yuav tsum zoo ib yam thoob plaws txhua qhov ntawm koj cov cai! Koj tseem tuaj yeem hloov kho qhov chaw kom siv qhov chaw hloov chaw (uas muaj qee qhov zoo).

Kauj Ruam 6: Cov lus pom

Tej zaum koj yuav tau pom tias kuv tau 'tawm tswv yim' ntawm cov cai kuv tshaj tawm ntawm kev tswj hwm ib feem. Koj tuaj yeem tawm tswv yim ib qho ntawm cov cai los ntawm kev tso tus # thiab cov kab uas seem yuav tau hais tawm. Thaum cov software raug suav sau cov lus tsis quav ntsej

# Nyob Zoo Ntiaj Teb

Cov lus pom yog tus cawm seej ntawm cov cai. Vim tias lawv tso cai rau koj los qhia txhua tus neeg hauv koj li chaws thiab koj xav li cas thaum sau cov cai. Tab sis tsis txhob overdo nws! Tshaj tawm cov cai tuaj yeem ua rau tsis zoo li cov lus hais hauv qab

Yog li thaum twg kuv yuav tsum tawm tswv yim kuv tus lej?

Kuv txoj cai ntawm tus ntiv tes xoo yog tawm tswv yim koj cov kev xav raws li koj sau, yog li yog koj ntxiv qhov sib txawv tsuas yog tuav koj lub hnub nyoog uas tsis muaj lwm lub hom phiaj. Tawm tswv yim tias.

# Hloov pauv uas tuav kuv lub hnub nyoog hauv xyoo # Tsis tau siv hauv qhov haujlwm no tab sis # qhov tseem ceeb rau kev muaj sia nyob ntawm tib neeg haiv neeg! kuv = 23

Kauj Ruam 7: Koj Ua tiav - Sijhawm Sau Ib Yam Koj Tus Kheej

Woah, koj nyuam qhuav kawm cov hauv paus ntawm nab hab sej!

Duab
Duab

Yog li "Kuv yuav ua dab tsi tam sim no?" koj yuav nug, zoo koj tuaj yeem txuas ntxiv ua si nrog koj cov ntaub ntawv. Thaum koj xav tias koj tau npaj txhij koj tuaj yeem ua qhov nyuaj. Sau ib qho program kom ntxiv lossis rho tawm ob tus neeg siv cov lej nkag mus. Siv internet los nrhiav seb yuav ua li cas thiaj tau txais cov neeg siv tswv yim ntxiv lossis rho tawm ob qhov kev nkag mus thiab nco ntsoov tawm tswv yim koj cov cai! Thaum Python yooj yim kawm nws los ntawm tsis muaj txhais tau tias muaj peev xwm qis qis - cov phiaj xwm ntawm txhua daim duab, qhov loj me thiab teeb tsa tau ua tau siv Python thiab nws tau nthuav dav (thiab feem ntau yog xa hauv zej zog) cov tsev qiv ntawv. Tshaj tawm koj cov cai hauv qab no rau cov lus qhia thiab txhim kho. Hmoov zoo!

Pom zoo: