Python 基础 1
1.解释性 可以直接从源代码运行程序.在计算机内部,Python解释器把源代码转换成称为字节码的中间形式,然后再把它翻译成计算机使用的机器语言并运行.
2.#符号后面的内容都是注释.
3.在字符串中行末的'\'表示下一行的内容和上一行是接着的;字符串前加一个r表示某些不需要转义符那样的特别处理的字符串;在处理文本文件的时候使用 Unicode字符串,特别是这个文件中包含有用非英语的语言写的文本;一定要用自然字符串表示正则表达式,不包括 char这个类型.
4.基本的数据类型包括数和字符串.数的类型包括:四类, 整数,长整数,浮点数和复数.
5.使用变量时,只需赋值给他们即可.
6.在逻辑行首的空白用来决定逻辑行的缩进层次,从而用来决定语句的分组.
7.运算符:'a'+'b'='ab','la'*3='lalala',3**4表示3的4次幂,//:取整除,%:取模,大于小于号可以任意连接,==比较对象是否相等,not 表示布尔非,and 布尔与,or 布尔或
相关文档:
16.1. select — Waiting for I/O completion¶
This module provides access to the select and poll functions available in most operating systems, epoll available on Linux 2.5+ and kqueue available on most BSD. Note that on Windows, it only works for sockets; on other operating systems, it al ......
这是一个简单的表达式计算器, 不太懂用Tkinter写GUI, 参考了别人的代码
from __future__ import division
from Tkinter import Tk, Entry, Button, Label, mainloop
from tkFont import Font
def get_value ():
v = ''
try:
v = eval(text.get()) #use eval to calculate the vlaue of the text
except:
pa ......
这是一个我们在处理中文时, 经常遇到的问题.
python里面基本上要考虑三种编码格式
1 源文件编码
在文件头部使用coding声明。告诉python解释器该代码文件所使用的字符集。
#/usr/bin/python
#coding: utf8
2 内部编码
代码文件中的字符串,经过decode以后,被转换为统一的unicode格式的内部数据,类似于u'*'。unic ......
1.常用方法,不带参数
def decator(func):
def inner_func(*args):
args = (i * 2 for i in args)
return func(*args)
return inner_func
@decator
def add(a, ......
'''gen_python_api.py generates a python.api file for SciTE
The generated api file includes
*) all Python keywords
*) all builtin functions
*) all module attributes
Module functions are represented by their docstring if available,
otherwise by the function definition from the source file. ......