Cov txheej txheem:

Python Tutorial No.1: 5 Cov Kauj Ruam
Python Tutorial No.1: 5 Cov Kauj Ruam

Video: Python Tutorial No.1: 5 Cov Kauj Ruam

Video: Python Tutorial No.1: 5 Cov Kauj Ruam
Video: Python Tutorial - Python Full Course for Beginners 2024, Hlis ntuj nqeg
Anonim
Python Tutorial No.1
Python Tutorial No.1

Qhov no yog kev qhia Python ua nrog tus pib ua tiav hauv siab. Cov lus qhia luv rau Python yuav pab koj nkag siab txog keeb kwm thiab nws yog dab tsi, ua ntej peb txav mus rau cov lus qhia. Python yog dab tsi? Nqa los ntawm www.python.org:

Nab hab sej yog lub hom phiaj rau cov lus programming uas siv tau rau ntau yam kev txhim kho software. Nws muab kev txhawb nqa zoo rau kev koom ua ke nrog lwm yam lus thiab cov cuab yeej, los nrog cov txheej txheem cov tsev qiv ntawv, thiab tuaj yeem kawm tau ob peb hnub. Muaj ntau tus nab npawb programmer qhia txog kev tsim khoom tau zoo thiab xav tau cov lus txhawb kev txhim kho kom zoo dua qub, muaj cai tswj tau ntau dua. Hauv lwm lo lus, Python yog ib qho yooj yim kawm, nyeem, thiab sau, ua kom ntseeg tau tias koj yuav nkag siab qhov koj tau sau ob peb hlis tom qab koj sau nws. Keeb Kwm Keeb Kwm ntawm Python. Python tau xeeb tub thaum xyoo 1980 los ntawm Guido van Rossum hauv tebchaws Netherlands ua tus ua tiav ntawm ABC cov lus programming, thiab nws sai sai sau cov neeg nyiam, tshwj xeeb tshaj yog tom qab nws tau tshaj tawm hauv GPL hauv version 1.6.1. thiab thawj tus neeg siv BitTorrent. Nws kuj tseem siv tau ntau yam los ntawm Google thiab NASA. Note: Cov lus qhia no tau raug kho tshiab thiab txhim kho los ntawm nws tus kws sau (ZN13) thiab tus koom tes (Hugo. B) yog li thov ua siab ntev thiab mus ntsib, koj yuav pom kev kawm Python tau txais txiaj ntsig zoo. ZN13 Hugo. B

Kauj ruam 1: Rub tawm Python

Rub tawm Python
Rub tawm Python

Txhawm rau program hauv Python koj yuav tsum rub lub Python libraries, thiab Integrated DeveLopment Environment, IDLEAs ntawm 16/6/07, tso tawm yog version 2.5.1Python Rub tawm ntawm no. Peb yuav xav tias koj siv windows ntawm no, tab sis yog tias koj tab tom siv ib qho Linux-based OS, nws yuav zoo li twb tau teeb tsa lawm. Yog xav paub, qhib console/konsole/davhlau ya nyob twg (txawv nrog distro), thiab typepython. Yog tias nws tau teeb tsa, Python cov kab hais kom ua yuav qhib Tom qab koj tau teeb tsa nws, mus Pib> Txhua Qhov Kev Pabcuam> Python> IDLE thiab peb yuav pib!

Kauj Ruam 2: Txoj Haujlwm Tso Tawm, Sau Nqe Lus, thiab "Nyob Zoo Ntiaj Teb"

Cov Txheej Txheem Tso Tawm, Sau Nqe Lus, thiab
Cov Txheej Txheem Tso Tawm, Sau Nqe Lus, thiab

Ntawm no peb yuav qhia koj ib yam ntawm thawj yam yuav luag txhua tus programmer kawm: yuav ua li cas luam tawm "nyob zoo ntiaj teb". Nws yog tus programmer qhov ua piv txwv piv txwv thawj zaug. Nco tseg, luam ntawv tsis txhais hais tias luam ntawv zoo li hauv tus lej thiab ntawv, nws tsuas yog txhais tau tias tso saib, lossis tso tawm.

>> print "Nyob zoo ntiaj teb"Thiab koj yuav tau txais cov txiaj ntsig ntawm

Nyob Zoo Ntiaj TebN. B. Koj xav tau cov cim ("") los qhia rau Python tias koj xav kom nws luam tawm, tsis li ntawd koj yuav tau txais qhov no

>> luam tawm nyob zoo worldSyntaxError: syntax tsis raugnrog "ntiaj teb" yuav hais txog xim liab, los qhia qhov koj ua tsis raug.

Kauj ruam 3: Variables

Ntau yam
Ntau yam
Ntau yam
Ntau yam

Qhov sib txawv (mus rau qhov zoo tshaj plaws ntawm kuv qhov kev paub) yog qhov txuas rau lwm daim ntawv: Kuv yuav qhia: Ntaus qhov no rau hauv IDLE:

>> myvar = "Nyob Zoo Ntiaj Teb!" >>> & apos & apos & aposprint & apos & apos & apos & apos myvarHello World!myvar yog qhov sib txawv hauv qhov piv txwv no, tab sis kuj tseem tuaj yeem ua tus lej. siv nws los hloov cov ntawv/cov ntaub ntawv hauv txoj hlua

>> luam tawm " %s yog tus lej %d!" %("Python", 1) Python yog tus lej 1!"%s" txhais tau tias yog hloov txoj hlua thaum "%d" qhia tias yuav tsum tau hloov tus lej.

Kauj Ruam 4: Txoj Haujlwm Tawm Tswv Yim thiab Raw_input () Muaj nuj nqi

Txoj Haujlwm Tawm Tswv Yim thiab Raw_input () Muaj nuj nqi
Txoj Haujlwm Tawm Tswv Yim thiab Raw_input () Muaj nuj nqi

Txoj hauv kev yooj yim tshaj plaws kom tau txais cov neeg siv tswv yim los ntawm kab hais kom ua yog nrog

raw_input ()Nws nyeem los ntawm tus qauv nkag thiab muab cov hlua rau tus sib txawv uas koj xaiv. Piv txwv, qhov no yog qhov nws siv

name = raw_input ("Sau koj lub npe ntawm no:") hnub nyoog = raw_input ("Sau koj lub hnub nyoog ntawm no:") luam tawm "Koj lub npe yog:", nameprint "Thiab koj yog", hnub nyoogThaum Python tus neeg txhais lus nyeem thawj kab, nws yuav luam cov ntsiab lus hauv kab lus (Sau koj lub npe ntawm no:), thiab thaum koj nkag koj lub npe, nws yuav mus rau kab tom ntej, ua tib yam, tab sis thaum nws los hla qhov "luam tawm" nqe lus nws luam tawm cov ntsiab lus hauv kab lus, thiab los hla "lub npe" uas yog qhov sib txawv, ib txwm ua raws li txuas rau cov ntsiab lus koj tau nkag ua ntej, nrog cov txiaj ntsig hauv qab no

>> Nkag mus rau koj lub npe ntawm no: Hugo. BEnter your age here: 16Koj lub npe yog: Hugo. BAnd koj muaj 16 xyooNyob rau theem no, nws yuav yog lub tswv yim zoo los qhia rau tus txheej txheem ntawm kev tawm lus. Ua li feem ntau cov ntawv sau thiab lus Unix-plhaub, tus hash lossis phaus (#) kos npe qhia tias cov lus pom pib los ntawm # thiab txuas ntxiv mus txog thaum Qhov kawg ntawm kab ntawv. Nco tseg, hauv IDLE, thaum twg koj ntaus tus # cim, nws thiab txhua cov ntawv hauv qab no ntawm kab ntawd tig liab. Yog li

#Ceeb toom !!! Qhov no yuav ua rau CPU siv tau txog li 100% !!! counter = 0while counter <1000000: counter += 1 print counter

Kauj ruam 5: Txuas ntxiv …

Ua haujlwm …
Ua haujlwm …

Qhov chaw nyob ib ntus: Tos tos cov ntsiab lus tshiab, thov ua siab ntev. H. B.

Pom zoo: