首頁  >  文章  >  後端開發  >  初級Python的學習之路

初級Python的學習之路

巴扎黑
巴扎黑原創
2017-08-02 13:29:401420瀏覽

在我們學習Python入門之後,我們就需要開始對Python的基礎進行學習,也就是初級階段的學習。接下來我們來看看Python的初級階段需要學習哪些東西。

1.語法

#!/usr/bin/python
# -*- coding: UTF-8 -*-

str = 'Hello World!'

print str # 输出完整字符串
print str[0] # 输出字符串中的第一个字符
print str[2:5] # 输出字符串中第三个至第五个之间的字符串
print str[2:] # 输出从第三个字符开始的字符串
print str * 2 # 输出字符串两次
print str + "TEST" # 输出连接的字符串

http://blog.csdn.net/u011955252/article/details/51273863

#2.運算方法

for(i=1;i<=n;++i)
{
for(j=1;j<=n;++j)
{
c[ i ][ j ]=0; //该步骤属于基本操作 执行次数:n^2
for(k=1;k<=n;++k)
c[ i ][ j ]+=a[ i ][ k ]*b[ k ][ j ]; //该步骤属于基本操作 执行次数:n^3
}
}

http://www.php.cn/python-tutorials-375819.html

3.函數

def square(x):
return x**2
>>> square
<function square at 0x031AA230>
>>> dir(square)
[&#39;__call__&#39;, &#39;__class__&#39;, &#39;__closure__&#39;, &#39;__code__&#39;, &#39;__defaults__&#39;, &#39;__delattr__&#39;, &#39;__dict__&#39;, &#39;__doc__&#39;, &#39;__format__&#39;,&#39;__get__&#39;, &#39;__getattribute__&#39;, &#39;__globals__&#39;, &#39;__hash__&#39;, &#39;__init__&#39;, &#39;__module__&#39;, &#39;__name__&#39;, &#39;__new__&#39;,&#39;__reduce__&#39;, &#39;__reduce_ex__&#39;, &#39;__repr__&#39;, &#39;__setattr__&#39;, &#39;__sizeof__&#39;, &#39;__str__&#39;, &#39;__subclasshook__&#39;,&#39;func_closure&#39;, &#39;func_code&#39;, &#39;func_defaults&#39;, &#39;func_dict&#39;, &#39;func_doc&#39;, &#39;func_globals&#39;, &#39;func_name&#39;]

#http: //www.php.cn/python-tutorials-375824.html

4.模組

http://www.php.cn/python-tutorials- 375825.html

5.資料流

import osnames = os.listdir(src)for name in names:
    srcname = os.path.join(src, name)
    fo = open(srcname, &#39;r&#39;)    for line in fo:        print line

http://www.php.cn/python-tutorials-375827.html

#

以上是初級Python的學習之路的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn