注释前缀 #
#!/usr/bin/python
#Filename:helloworld.py
print 'Hello Python.'
#Filename:helloworld.py
print 'Hello Python.'
字符串
1. '和"是一样的
2. '''用来定义多行字符串,并且其中可自由使用'和"
>>> print '''This is a multi-line string. this is 1st line.
this is second line.
"what's ur name?", I asked.
"my name is fourth line!".'''
This is a multi-line string. this is 1st line.
this is second line.
"what's ur name?", I asked.
"my name is fourth line!".
this is second line.
"what's ur name?", I asked.
"my name is fourth line!".'''
This is a multi-line string. this is 1st line.
this is second line.
"what's ur name?", I asked.
"my name is fourth line!".
>>>
3. 转义字符 \
4. 自然字符串前缀,r或R
自然字符串:即不识别转义字符的串。
5. Unicode字符串前缀,u或U
6. 放在一起的字符串会自动级联
7. ,分开的输出内容,和级联类似,但会自动添加一个空格
>>> print 'this is' "a sentence."
this isa sentence.
>>> print 'this is',"a sentence."
this isa sentence.
>>> print 'this is',"a sentence."
this is a sentence.
语句分隔
用 ; 或 物理行的结束 来表示语句的结束。
但通常在py中看不到分号 ;
i = 5
print i
print i
i = 5;print i
i = 5;print i;
i = 5;
print i;
print i;
程序块的划分
使用缩进来表示程序的层次
建议用 单个制表符 或 两或四个空格
运算符
1. **,幂,x**y,返回x的y次幂.
2. //, 整除。返回商的整数部分。
3. ~,按位翻转,~x返回-(x+1), ~5得到-6。
4. not,and,or,逻辑运算符。