我的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
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
相关文章推荐
- 我的Python学习之路之基本语法-面向对象编程
- Python学习之路-简单语法
- Python学习之路——语句和语法
- Python学习之路☞1——Python及基础语法
- 我的Python学习之路之基本语法--参数传递、文件操作
- python学习之路:语法基础
- 我的Python学习之路之基本语法-列表和字典
- 我的Python学习之路之基本语法-输入输出
- 王亟亟的Python学习之路(三)-基础语法以及基本数据类型
- 王亟亟的Python学习之路(三)-基础语法以及基本数据类型
- 我的Python学习之路之基本语法-函数
- Python学习笔记——Python开发中基本的语法1
- python小白学习之路啊
- 我的python学习之路-08
- python学习语法
- 学习python--基础语法
- python学习之路之案例3--多级菜单显示城市详细信息
- 学习python之路---python小算法总结(一)
- java学习之路之基本语法之关键字、保留字、标识符。
- python学习之路4------列表生成器