Python基础学习笔记(一)入门

  参考资料:

  1. 《Python基础教程》

  2. http://www.runoob.com/python/python-chinese-encoding.html

  3. http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000

  

    ▶ 中文编码

   Python中默认的编码格式是ASCII格式。如想支持中文,则在文件开头加入# -*- coding: UTF-8 -*- 或者 #coding=utf-8即可。

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

print "你好,世界";

运行结果:

 

 两种函数使用方式

print "Hello, Python!";

print ("Hello, Python!");

 

  ▶ 脚本式编程

$ python test.py

 

▶ Python标识符

标识符有字母、数字、下划线组成。

▼ 标识符不能以数字开头,且是区分大小写的。

▼ 在Python中下划线开头的标识符是由特殊意义的。1. 以单下划线开头的(_foo)的代表不能直接访问的类属性,需通过类提供的借口进行访问,不能通过“from xxx import *”而导入。2. 以双下划线开头的(__foo)代表类的私有成员;3. 以双下划线开头和结尾的(__foo__)代表Python里特殊方法专用的标识,如__init__代表类的构造函数。

Python通过缩进来写模块。如果缩进格式不对,则会产生如下异常:

IndentationError: unexpected indent

IndentationError: unindent does not match any outer indentation level

  Python使用斜杠(\)将一行的语句分为多行显示,而语句中如果含有[],{}或()括号,就不需要使用多行连接符。

    Python中单行注释采用#开头。

    Python中语句之间使用分号(;)分割。

 

   ▶ 等待用户输入

#!/usr/bin/python

raw_input("\n\nPress the enter key to exit.")

   

  ▶ 命令行参数

help("keywords/module/modules yourstr/topics")

  更多

 

posted @ 2015-10-07 16:12  motein  阅读(200)  评论(0编辑  收藏  举报