<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 四、Python語言簡單介紹 ----From a high school student'sview to learn Python 關鍵字:高中生 學編程 Python語言 Python語言安裝 (一)、下載和安裝Python 下載Python最直接的方法就是訪問它的官網([www.python.org](http://www.python.org)),然后點擊屏幕左側的?“download”選項。點擊之后就會進入如下的界面: [![四、Python語言簡單介紹](https://box.kancloud.cn/d697f9b22a73843d39c21a67e360978b_955x540.jpg "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbGnJAch91&690) 接下來大家就可以根據自己電腦的系統來選取各自的下載資源,在電腦平臺中,主要還是針對Win,Unix, Mac OSX這三大平臺。但是Python可應用的平臺十分廣泛,不僅僅是前面所提到的電腦平臺,手機平臺上也可以進行Python語言的學習與使用,例如:Android,IOS等等。 注意:因為這個教程針對的是Python3.0以下的版本,所以大家最好選擇Python 2.7.5來下載。而為什么選擇Python2.7.5呢,是因為Python3.0的升級是革命性的,把以前的一些特性拋棄了,當然也引入了很多新的特性,因此并不具備向前的兼容性,而且許多的第三方軟件并沒有針對Python3.0進行移植,所以還是Python2.7.x更實用。 在下載完成之后就直接進行安裝,安裝時我們盡量選擇按照提示的缺省目錄來進行操作,然后我們就可以來運行Python了。 (二)、運行Python 總體來說有三種方法來運行Python,今天先向大家介紹前兩種較為簡單的運行方法。 (1)?????在命令行上啟動解釋器 按Windows鍵+R,輸入CMD [![四、Python語言簡單介紹](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8NJzz49&690) ![](https://box.kancloud.cn/fcfb77cec2bdc5ca68dcb8a7f92a5a44_723x364.jpg) 之后找到python目錄,運行python [![四、Python語言簡單介紹](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8RPsx8d&690) ![](https://box.kancloud.cn/a237a696a464a4d7c30d3a269b2ad379_846x690.jpg) 顯示如下: [![四、Python語言簡單介紹](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8Mx8Na5&690) ![](https://box.kancloud.cn/3f965443db4d6cd9a0eddbf7be5cd0ff_846x165.jpg) 我們就可以打開命令行來編寫最簡單的代碼了。但是這種命令行只能每次輸入一行代碼來執行,效率太低。 (2)????在簡單的集成開發環境內運行 這里所說的簡單集成環境就是IDLE,它適合去編輯一些簡單短小的代碼,對于初學者來說是完全夠用的。 IDLE在哪呢?如果按照缺省目錄安裝則在:C:\Python27\Lib\idlelib [![四、Python語言簡單介紹](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8MW7Qce&690) ![](https://box.kancloud.cn/29f706f87d84713ae38018192d23428d_846x319.jpg) 或者直接在搜索目錄中查找IDLE然后運行,就會出現如下窗口: [![四、Python語言簡單介紹](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8M6R7f5&690) ![](https://box.kancloud.cn/76bca3949ab47e7232946f45bd537c8e_846x221.jpg) 接下來點擊左上角的File然后選擇NewWindow就可以通過新的File來編寫代碼了。 [![四、Python語言簡單介紹](https://box.kancloud.cn/bfea4b6df70752b35575f7fbed8dfdd8_846x217.jpg "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8VAwJ35&690) 在編寫完一個程序后,將文件保存為類型為.py的文件,點擊菜單“run”,再點擊”RunModule”或者直接按“F5”鍵運行。 [![四、Python語言簡單介紹](https://box.kancloud.cn/839da6280bc0ae75cd31e5fce148ceb9_846x269.jpg "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8XZog7c&690) 之后,如果運行正常,彈出的窗口中就會顯示運行的結果: [![四、Python語言簡單介紹](https://box.kancloud.cn/1fe1aa59209d96ac148aff0adfe50cfc_857x246.jpg "四、Python語言簡單介紹")](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbG8WLoE64&690) (3)第三種方法 還有一些第三方的專門的軟件可以用來進行Python的開發,而且比上面介紹的兩種方法都高級,但是工具的安裝比較復雜,我們還是先把精力用在語言學習上吧,等后續有必要的時候在介紹。 作為一門解釋性的語言,Python的簡潔與純粹使用提供了一個更加快速的開發環境,Python的語法十分簡單,更加易懂,相比于C++和JAVA來說用Python編程可以生許多時間。?并且Python適用范圍廣泛,它最大的優勢就是在網頁的編輯上,但是在和計算機的“底層”打交道時(例如直接操控一些硬件),Python的效率就會相當低下,但是它是十分適合沒有計算機語言基礎的初學者來學習。 (三)、Python的快速介紹 Python包含的主要元素: 1. 輸入與輸出 一般的,在Python中想要輸入一些內容,只需要在平臺中打出你想要的內容即可,而輸出程序則是用print函數來進行。 2. 注釋 ?注釋就是在寫代碼的過程中,程序員希望用一些語句來幫助他在以后返回看自己所寫的程序,而這些語句并不能夠出現在真正的代碼當中。所以在Python中,語句一般用#標示注釋,從#開始到一行結束都是注釋。 例: <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:14px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(203,203,203) rgb(66,146,135) rgb(203,203,203) rgb(203,203,203); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p></td><td valign="top" style="width:400.4px; height:14px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(203,203,203) rgb(203,203,203) rgb(203,203,203) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">print (“hello”) # commentone</span></p></td></tr></tbody></table> 注釋還有一種方式就是使用三個”””,在后面的程序中會有使用及說明。 3. 操作符 操作符就是大家日常學習工作中會用到的一些符號,像+、-、*、/、//、**(乘方)、%等標準操作符,還有一些比較操作符,像< ?>?<=?>= ?==?!=(不等于)<>(判斷兩個數不相等)。 還有一些邏輯操作符:and?or?not。這些操作符大家可以在命令行中或者IDLE中自己試一下。 例: <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:185px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(203,203,203) rgb(66,146,135) rgb(203,203,203) rgb(203,203,203); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">6</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">7</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">8</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">9</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">10</span></p></td><td valign="top" style="width:400.4px; height:185px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(203,203,203) rgb(203,203,203) rgb(203,203,203) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;3+5</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">8</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;3&lt;4</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">True</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;3!=4</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">True</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;2&gt;4 and 3&lt;4</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">False</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;2&gt;4 or 3&lt;4</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">True</span></p></td></tr></tbody></table> 4. 變量和賦值 ?變量簡單來說就是類似于方程中的x,y這一類有名字的元素,變量名就是一些字母開頭的標示符,中間可以帶有數字,下劃線等。變量的賦值就是把變量和數字用等號連接起來,從而給變量一個具體的值。賦的值并不一定要是數字,也可以是字符串(接下來會介紹)。 <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:109px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(203,203,203) rgb(66,146,135) rgb(203,203,203) rgb(203,203,203); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">6</span></p></td><td valign="top" style="width:400.4px; height:109px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(203,203,203) rgb(203,203,203) rgb(203,203,203) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;start=2</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;start</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;second="two"</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;second</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">'two'</span></p></td></tr></tbody></table> 5. 數字 ?Python中支持五中基本數字類型,分別是: 1) 有符號整型:int? 如:231 ? 56? -342 2) 長整數 <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:26.6px; height:128px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(203,203,203) rgb(66,146,135) rgb(203,203,203) rgb(203,203,203); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">6</span></p></td><td valign="top" style="width:361.9px; height:128px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(203,203,203) rgb(203,203,203) rgb(203,203,203) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;a=1234569l</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;type(a)</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&lt;type'long'&gt;</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;b=-12345678901234567890123l<wbr/></span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;type(b)</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&lt;type'long'&gt;</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;?<wbr/></span></p></td></tr></tbody></table> 注意后面有一個“L”跟著。?? 3) 布爾型:bool ?True ? False 在這里要說的是布爾型是一個特殊的整型,但是要把它放在一個數字的環境中時,Treu用1表示,而False用0表示 4) 浮點型:float ?3.1423 5) 復數:complex? 0+73j ? -32-549j 6.字符串 ?在Python中字符串被定義成引號之間字符的集合。Python中可以對字符串進行多種操作,包括索引,切片,串聯字符串,重復字符串等等。 [![四、Python語言簡單介紹](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "四、Python語言簡單介紹")![](https://box.kancloud.cn/6c492e551820ebb7686c1d365cb402bb_521x69.jpg)](http://photo.blog.sina.com.cn/showpic.html#blogid=d6cca93e0101ejcj&url=http://album.sina.com.cn/pic/d6cca93egx6DbIRU3oW66&690) 綠色的部分就是字符串 7. 列表和元組(list andtuple) ?列表和元組可以被認為是普通的數組,它能夠包含任意數量,任意類型的Python對象,但是列表和元組之間還是有一定的區別。列表用中括號([])來包括,列表中元素的個數和元素的值均可以被改變,而元組則用小括號(())包括,而且元素不可以被更改。下邊是列表和元組的例子: <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:109px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(0,0,0) rgb(66,146,135) rgb(0,0,0) rgb(0,0,0); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">6</span></p></td><td valign="top" style="width:400.4px; height:109px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;alist=[1, 2, 3, 4, 'hello']</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;alist</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">[1, 2, 3, 4,'hello']</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;atuple=(1, 2, 3, 4, 'hello', 'Python')</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;atuple</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">(1, 2, 3, 4, 'hello','Python')</span></p></td></tr></tbody></table> 現在看上去似乎列表和元組沒有什么區別,但是在之后的內容中我會想大家詳細的介紹各種對于列表和元組的操作。 8. 字典 ?字典是Python中的映射數據類型,其實簡單上來說就是把一些對象賦值,這些對象在字典中稱為鍵,而賦的值也可以是任意類型的Python對象,字典元素用大括號({})包括,如果要取出一些字典中的鍵,則用中括號來包裹元素。在接下來的內容中會向大家詳細介紹字典。例如: <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:90px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(0,0,0) rgb(66,146,135) rgb(0,0,0) rgb(0,0,0); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p></td><td valign="top" style="width:400.4px; height:90px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;first_Dict={ 'Hello': 'Python', 'First': 1}</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;first_Dict</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">{'First': 1, 'Hello':'Python'}</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;first_Dict ['Hello']</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">'Python'</span></p></td></tr></tbody></table> 9. Python語法中的縮進對齊 ??Python中經常用縮進對齊來表示代碼的邏輯,而不是使用大括號。這使得程序的可讀性更高,但是對于一個Python的初學者來說,僅使用縮進可能會使他感到奇怪并且十分的困惑,而且會非常的不適應。在我一開始學習的時候就經常因為縮進的距離錯誤導致程序無法運行。但是在我使用這種方式一段時間以后,我發現其實并不是太困難去接受。 10. if 語句 if語句是Python中最為基礎的語句,它的意思簡單來說就是如果一個條件被滿足,就會向下執行下面的條件,這就相當于是一個條件語句,我們可以來看幾個例子: <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:90px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(0,0,0) rgb(66,146,135) rgb(0,0,0) rgb(0,0,0); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p></td><td valign="top" style="width:400.4px; height:90px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;x=-1</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;if x&lt;0:</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">...?<wbr>?<wbr>print('hello')</wbr></wbr></span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">...</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">hello</span></p></td></tr></tbody></table> ?這是一段十分簡單的代碼,那么大家就可以看到了,if語句就相當一個條件滿足了之后就會運行下一層的代碼,但是在if語句下的一層代碼要注意縮進。 11. while循環 ?while循環語句的語法與if語句的時分類似,但是while是一個循環語句,它會一直不斷的執行循環,直到表達式的值變成0或者False,我們來看下例子: <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:166px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(0,0,0) rgb(66,146,135) rgb(0,0,0) rgb(0,0,0); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">6</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">7</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">8</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">9</span></p></td><td valign="top" style="width:400.4px; height:166px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;x=1</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;while x&lt;5:</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">...?<wbr>?<wbr>print('circle#% x' % x)</wbr></wbr></span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">...?<wbr>?<wbr>x+=1</wbr></wbr></span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">...</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">circle # 1</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">circle # 2</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">circle # 3</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">circle # 4</span></p></td></tr></tbody></table> ?這就是最簡單的while循環語句,如果不給它一個結束條件的話,循環就會一直進行下去,而且也要注意縮進。接下來的內容會向大家詳細介紹while循環。 12. for循環 for循環不同于while循環的是for循環通常是包含一個徐序列,就像是在以區間內執行一個循環一樣,例如range(),列表和元組甚至是字典內執行循環,例如: <table cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-collapse:collapse"><tbody><tr><td valign="top" style="width:30.1px; height:147px; border-style:solid; border-width:1px 3px 1px 1px; border-color:rgb(0,0,0) rgb(66,146,135) rgb(0,0,0) rgb(0,0,0); padding:2.5px"><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">5</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">6</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">7</span></p><p style="margin:0px 0px 5px; text-align:right; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">8</span></p></td><td valign="top" style="width:400.4px; height:147px; border-style:solid; border-width:1px 1px 1px 3px; border-color:rgb(0,0,0) rgb(0,0,0) rgb(0,0,0) rgb(66,146,135); padding:2.5px"><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;alist=[1, 2, 3, 4]</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">&gt;&gt;&gt;for i in alist:</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">...?<wbr>?<wbr>print(i)</wbr></wbr></span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">...</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">1</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">2</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">3</span></p><p style="margin:0px 0px 5px; font-size:12px; line-height:normal; font-family:Arial; color:rgb(2,28,161)"><span style="letter-spacing:0.0px">4</span></p></td></tr></tbody></table> 就像上面這個循環中所說的,for循環是在給定的alist之中執行的,而while循環則沒有這些條件。 我的更多文章: - Python程序調試的一些體會(2013-10-06 22:57:35) - 十四、Python編程計算24點(之二)(2013-10-03 22:18:28) - 十三、Python編程計算24點(之一)![](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "此博文包含圖片") (2013-10-02 22:15:46) - 十二、Python簡單數據結構應用(之二)(2013-10-02 22:10:41) - 十一、Python簡單數據結構應用(之一)(2013-09-23 23:31:49) - 十、Python編程解決組合問題(之二)![](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "此博文包含圖片") (2013-09-21 23:37:27) - 九、Python編程解決組合問題(之一)(2013-09-21 23:32:54) - 八、Python的函數編程(之二)![](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "此博文包含視頻") (2013-09-20 23:09:39) - 七、Python的函數編程(之一)![](https://box.kancloud.cn/2015-10-30_5632e1cc04fc3.gif "此博文包含視頻") (2013-09-20 23:09:10) - 高中生如何學編程(2013-09-02 19:26:01)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看