您的位置:首页 > 编程语言 > Python开发

我的python学习之路----语法

2011-09-05 14:21 357 查看
1、变量

python变量不需要声明变量类型,通过=号进行赋值,如

str = 'hello'

div = 20/3

2、数学计算

>>> 10/3

3.3333333333333335

>>> 10//3

3

>>> 10//-3

-4

>>> 10%3

1

>>>

3、字符串

使用单引号或者多引号定义,使用""" """定义多行文本。

>>> """hello

world"""

'hello\nworld'

4、注释

python的单行注释以#号开始,如:

str = 'hello' #strng variable

python本身并不提供多行注释,如果要使用多行注释,可以使用

if 0:

包含多行文字

5、打印

打印字符串:

print(value1,value2,...),如:

>>> print(s,"hello")

fdsfa hello

格式化输出值:

>>> strHello = "the length of (%s) is %d" %('Hello World',len('Hello World'))

>>> print(strHello)

the length of (Hello World) is 11
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: