資源描述:
《python入門教程》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Python入門教程1----PythonSyntax1Python是一個(gè)高效的語言,讀和寫的操作都是很簡單的,就像普通的英語一樣2Python是一個(gè)解釋執(zhí)行的語言,我們不需要去編譯,我們只要寫出代碼即可運(yùn)行3Python是一個(gè)面向?qū)ο蟮恼Z言,在Python里面一切皆對(duì)象4Python是一門很有趣的語言5變量:一個(gè)變量就是一個(gè)單詞,只有一個(gè)單一的值練習(xí):設(shè)置一個(gè)變量my_variable,值設(shè)置為10?[cpp]?#Writeyourcodebelow!?my_variable=10???3第三節(jié)????1Python里面有三種數(shù)據(jù)類型interage,floats,boolean
2、s??2Python是一個(gè)區(qū)分大小寫的語言??3練習(xí)????1把變量my_int值設(shè)置為7????2把變量my_float值設(shè)置為1.23????3把變量my_bool值設(shè)置為true[python]?#Setthevariablestothevalueslistedintheinstructions!?my_int=7?my_float=1.23?my_bool=True??6Python的變量可以隨時(shí)進(jìn)行覆蓋??2練習(xí):my_int的值從7改為3,并打印出my_int????[python]?#my_intissetto7below.Whatdoyouthink?#willha
3、ppenifweresetitto3andprinttheresult????my_int=7???#Changethevalueofmy_intto3online8!?my_int=3???#Here'ssomecodethatwillprintmy_inttotheconsole:?#Theprintkeywordwillbecoveredindetailsoon!???printmy_int??7Pyhton的聲明和英語很像8Python里面聲明利用空格在分開??3練習(xí):查看以下代碼的錯(cuò)誤[python]?defspam():?eggs=12?returneggs??prin
4、tspam()??9Python中的空格是指正確的縮進(jìn)??2練習(xí):改正上一節(jié)中的錯(cuò)誤[python]?defspam():???eggs=12???returneggs???????printspam()??10Python是一種解釋執(zhí)行的語言,只要你寫完即可立即運(yùn)行??2練習(xí):設(shè)置變量spam的只為True,eggs的值為False?[python]?spam=True?eggs=False??11Python的注釋是通過“#”來實(shí)現(xiàn)的,并不影響代碼的實(shí)現(xiàn)??2練習(xí):給下面的代碼加上一行注釋[python]?#thisisacommentsforPython?mysterious
5、_variable=42??12Python的多行注釋是通過“""""""?”來實(shí)現(xiàn)的??2練習(xí):把下面的代碼加上多行[python]?"""?thisisaPythoncourse?"""?a=5??13Python有6種算術(shù)運(yùn)算符+,-,*,/,**(冪),%??2練習(xí):把變量count_to設(shè)置為1+2[python]?#Setcount_toequalto1plus2online3!?count_to=1+2?printcount_to???14Python里面求x^m,寫成x**m??2練習(xí):利用冪運(yùn)算,把eggs的值設(shè)置為100[python]?#Seteggsequa
6、lto100usingexponentiationonline3!?eggs=10**2?printeggs??1練習(xí):????1寫一行注釋????2把變量monty設(shè)置為True????3把變量python值設(shè)置為1.234????4把monty_python的值設(shè)置為python的平方[python]?#thisisaPython?monty=True?python=1.234?monty_python=python**2?Python入門教程2----TipCalculator1把變量meal的值設(shè)置為44.50[python]?#Assignthevariablemealt
7、hevalue44.50online3!?meal=44.50??1把變量tax的值設(shè)置為6.75%???[python]?meal=44.50?tax=6.75/100??1設(shè)置tip的值為15%??[python]?#You'realmostthere!Assignthetipvariableonline5.?meal=44.50?tax=0.0675?tip=0.15??1把變量meal的值設(shè)置為meal+meal*tax[python]?#Reassignme