Python变量

变量是计算机内存中的一块区域,变量 可以存储规定范围内的值,而且值可以改变

python下变量是对一个数据的引用

变量的命令

-变量名由字母、数字、下划线组成。

-变量不能以数字开头

-不可以使用关键字

-a ai _a

变量的赋值

-是变量的声明和定义的过程

a = 1

id(a)

Out[2]: 32300352 表示内存区域

Python变量

运算符与表达式

python运算符包括

-赋值运算符

-算术运算符

-关系运算符

-逻辑运算符

表达式是将不同的数据(包括变量、函数)用运算符号按一定规则连接起来的一种式子

Python变量

带引号的通常表示字符串,不带引号的通常表示变量

查看x类型

Python变量

Python变量

/除

//整除

%取余

Python变量

成立返回true

不成立放回false

Python变量

not表示取反

从上到下优先级越来越高

Python变量

Python变量

input("please input:")

Python变量

raw_input("please input:")

Python变量

编写一个四则运算器

#!/usr/bin/python


num1 = input("Please a number: ")
num2 = input("Please a number: ")


print num1 + num2
print num1 - num2
print num1 * num2

print num1 / num2

Python变量

显示运算过程

#!/usr/bin/python


num1 = input("Please a number: ")
num2 = input("Please a number: ")


print "%s + %s = %s" % (num1,num2,num1+num2)
print "%s - %s = %s" % (num1,num2,num1-num2)
print "%s * %s = %s" % (num1,num2,num1*num2)

print "%s / %s = %s" % (num1,num2,num1/num2)

Python变量


相关文章:

  • 2021-07-13
  • 2021-12-24
  • 2021-11-22
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2022-01-24
  • 2021-04-24
  • 2021-05-12
  • 2021-04-09
相关资源
相似解决方案