初级Python的学习之路


本文摘自php中文网,作者巴扎黑,侵删。

在我们学习Python入门之后,我们就需要开始对Python的基础进行学习,也就是初级阶段的学习。接下来我们来看看Python的初级阶段需要学习哪些东西。

1.语法

1

2

3

4

5

6

7

8

9

10

11

#!/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.运算方法

1

2

3

4

5

6

7

8

9

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.函数

1

2

3

4

5

6

def square(x):

return x**2

>>> square

<function square at 0x031AA230>

>>> dir(square)

['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__','__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__','__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__','func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']

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

4.模块

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

5.数据流

1

2

3

import osnames = os.listdir(src)for name in names:

    srcname = os.path.join(src, name)

    fo = open(srcname, 'r')    for line in fo:        print line

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

以上就是初级Python的学习之路的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

hash()是Python内置的吗

笔记之 Python正则表达式

Python如何把数字变成日期

使用Python将数组的元素导出到变量中(unpacking)

Python对json的解析详解

使用Python通过win32 com打开excel并添加sheet的方法

Python是怎么计算auc指标的?

Python如何示例爬虫代码

Python中关于range与xrange探究详解

Python中流程控制语句的详细介绍

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...