21 Mar 2009

Python学习笔记 - 1:数值和字符串类型

本文主要有: 数值类型和字符串类型
----------------------------------
数值类型:


整形: 1234,4,60...
长整形: 120L, 40l(不是数字,是小写L). python的长整形很NB,与系统无关,可以表示任意大小,直到内存上限.
浮点数: 123.45, 1.2345e+02
虚数: 1.2+3.4J, 1.2+3.4j
八进制: 合格的八进制前加0,例如0644
十六进制: 合格的十六进制前加0x,例如0x100fea8


字符串类型:

python支持2种字符串:Ascii字符串和Unicode字符串.

默认的即是Ascii字符串,通常可用单引号('),双引号("),三引号("""或者''')定义.字符串不能混用,前后要一致.例如:

>>> a = 'string1'
>>> b = "string2"
>>> c = """string3"""


Unicode字符串可以表示多字节的国际字符串.用u或者U来引导,例如:

>>> d = u'中国-My love'
>>> e = u'Hello world'


当然所有的以上两种字符串都可以加r或者R前缀表示原始字符串(如此就不再需要对特殊字符转义,例如',\等,参看下例).

>>> a = r"It's my book"
>>> print a
It's my book
>>> b = r"c:\windows"
>>> print b
c:\windows


其实字符串可以看做一个字符列表(list),可以使用索引得到某个字符,也可以使用切片(slice)操作得到子串.但没有append等列表方法.例如:

>>> a = r"It's my book"
>>> print a
It's my book
>>> a[1]
't'
>>> a[2]
"'"
>>> a[4]
' '
>>> c = a[5:8]
>>> print c
my 
>>> a.append('a')

Traceback (most recent call last):
File "", line 1, in 
a.append('a')
AttributeError: 'str' object has no attribute 'append'

18 Mar 2009

Fix compile ERROR using Geany

If you meet the following error while compile C file by using Geany.

18:53:55: 无法执行“ /home/daniel/code/test”(请确保已生成)
18:53:55: 执行虚拟终端程序失败
Check the option under Build menu, and change the compile parameters as

##CONTINUE##

gcc -Wall -o "%e" "%f"
Then you can use the buttons in toolbar to compile and execute programmes.

由于geany的默认设置下,工具栏那个编译按钮并没有生成可执行文件,所以需要手动更改,加上-o参数来指定生成文件即可.

17 Mar 2009

S5: A Simple Standards-Based Slide Show System

As described in the title, S5 file is a simple slide show format compared to Microsoft PowerPoint system. It is based entirely on XHTML, CSS, and JavaScript. You can set up a complete slide show with ONLY one single file. I have tried to use this during my dissertation presentation. What's more? It's rather easy with high compact coding style, just like writing a HTML webpage.

Want to know more? Following the link below:
##CONTINUE##
http://meyerweb.com/eric/tools/s5/

S5文件格式是一个快速/方便的单文件演示系统,比起微软的ppt文件更容易上手些,前提是你要会写一点html代码.曾经准备在毕设答辩的时候用,可惜发现的太晚,当时ppt已经做完了,几十页就懒得换了.

15 Mar 2009

Dev-C++ Error: stray '\161' in program

If you got error like "stray '\161' in program" under Dev-C++ environment, it means you have used SBC case punctuations. It would be all right if you replace them by DBC case ones.

BTW: it's a common error under GCC, especially if you use Asia language in your code.
##CONTINUE##
编译程序老是报stray '\161' in program错误,google了一下,发现是由于全角/半角符号引起,如果你是从别处复制的代码,或者有中文注释,不小心加个中文标点,都会出这个错.重新敲下代码或者全部改成半角就ok了.

这是gcc一个典型报错.

14 Mar 2009

Basic4GL

Basic4GL, a funny BASIC language for OpenGL programming under Win32. What's more? A free software, a fair compiler, an amazing IDE which allows you using BASIC language to write 2D or 3D applications.

Basic4GL is a free BASIC programming language for Win32 platforms with built in OpenGL v1.1 support.
Basic4GL is a compiler and virtual machine, using a easy, simple syntax based on traditional BASIC. It is designed to be an easy to learn, easy to use language for writing games, 3D demos and utilities without all the setup hassle associated with most language compilers.
##CONTINUE##

Basic4GL was written for anyone who:

  • Wants a free, easy to learn language to get into programming
  • Wants to learn OpenGL, or wants an easy to use environment for playing around with OpenGL, testing out ideas, making concept prototypes, e.t.c
  • Wants to write 3D games and demos.

If you want to know more, please following the link:
http://www.basic4gl.net/

3.14 - Birthday of π


π, the most magic number. 3.14 - birthday of π
If you want to know more about it, please follow these links:

http://3.1415926.com/

http://3.1415926535897932384626433832795028841971693993751058209.maxg.org/pi_full.html

Here is a song for it:

Click to Download it

##CONTINUE##

Pi = 3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679
8214808651 3282306647 0938446095 5058223172 5359408128 4811174502 8410270193 8521105559 6446229489 5493038196
4428810975 6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 4543266482 1339360726 0249141273
7245870066 0631558817 4881520920 9628292540 9171536436 7892590360 0113305305 4882046652 1384146951 9415116094
3305727036 5759591953 0921861173 8193261179 3105118548 0744623799 6274956735 1885752724 8912279381 8301194912

9833673362 4406566430 8602139494 6395224737 1907021798 6094370277 0539217176 2931767523 8467481846 7669405132
0005681271 4526356082 7785771342 7577896091 7363717872 1468440901 2249534301 4654958537 1050792279 6892589235
4201995611 2129021960 8640344181 5981362977 4771309960 5187072113 4999999837 2978049951 0597317328 1609631859
5024459455 3469083026 4252230825 3344685035 2619311881 7101000313 7838752886 5875332083 8142061717 7669147303
5982534904 2875546873 1159562863 8823537875 9375195778 1857780532 1712268066 1300192787 6611195909 2164201989
...