Python初学(1)

最近在学习python,以后想编写一些工作中用的到的脚本。python的入门我选择了《python从初学到入门》,这篇文章我会跟进我的学习进度。算是一个笔记吧。

我本身是熟悉C语言的,看python程序时里面很多概念都是有过接触,所以学习起来还算比较轻松。

Geany是一种常用的文本编辑器,使用方便并且功能强大,我第一次接触也觉得很好用,我接下来也都是使用这个文本编辑器进行学习在windos环境下。

在python中,用引号括起的都是字符串,引号可以是单引号,也可以是双引号。

python中有方法的概念,方法是python可对数据执行的操作。熟练使用可以极大的加快我们的开发速度。接下来列举几个字符串中的方法。

1 name="love python"
2 print=(name.title())     #title()方法以首字母大写的方式显示每个单词
3 print=(name.upper())     #全部改为大写输出    
4 print=(name.lower())     #全部改为小写输出

这些代码输出如下

1 Love Python
2 LOVE PYTHON
3 love pytho

通过方法拼接,python可以使用加号(+)来合并字符串

方法rstrip()可以找出字符串末尾、多余的空白并删除。方法lstrip()可以删除字符串开头空白,方法strip()可以删除字符串两端空白。

python使用两个乘号表式乘方运算。

1 >>>3**2
2 9

方法str()将非字符串值表示为字符串。在print输出时尤其注意

注释用#,和c语言不同。

在python终端会话框中执行命令import this,可以看到pyhton之禅--pyhton代码的指导原则。

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

这一部分主要是些基础的内容,让我从其他语言过度到python,开始熟悉。

猜你喜欢

转载自www.cnblogs.com/dubrother/p/9693604.html