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

【学习笔记】Python基础-数据类型与变量

2017-12-08 19:52 1211 查看

注释

注释符号为#

# hello world


字符串

使用单引号或者双引号都可以

print("hello world")
print('hello world')


转义符号 \

转义单引号

输入I’am python

print("I\'am python")


换行符 \n

这个在JAVA和C语言都非常常用的说

代码

print("I\'am python \nI am su")


运行结果

D:\PythonProject>python helloworld.py
I'am python
I am su


布尔值

代码

print("3 > 5 is ", 3 > 5)
print("3 < 5 is ", 3 < 5)


运行结果

D:\PythonProject>python helloworld.py
('3 > 5 is ', False)
('3 < 5 is ', True)


注意大小写

代码

print("True or False ", True or False)
print("True and False ", True and False)


运行结果

D:\PythonProject>python helloworld.py
('True or False ', True)
('True and False ', False)


空值 None

Java语言空值用null表示

代码

a = None
print(a)


运行结果

D:\PythonProject>python helloworld.py
None


变量

变量就是用来赋值的,注意小写哦

代码

a = None
print(a)
a = 5
print(a)
a = "hello world"
print(a)


运行结果

D:\PythonProject>python helloworld.py
None
5
hello world


动态变量

python这点确实和java不同,java的变量是要声明类型的,比如int a = 5,a = “hello”就绝对会出错,社会啊社会,Python请受我一拜

常量

习惯上大写表示

代码

PI = 3.1415
print(PI)


运行结果

D:\PythonProject>python helloworld.py
3.1415
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息