import keyword#关键字序列 区分大小写
print("python keyword不能用作变量名")
print("python keyword:",keyword.kwlist)
print("个数",':',len(keyword.kwlist))
#无需定义变量类型
variable_number=1
variable_name="variable"
print("variable_number的数据类型是:",type(variable_number))
print("变量名:",variable_name,"变量值:",variable_number)
#自动动态修改变量类型
variable_number="variable"
print("variable_number的数据类型是:",type(variable_number))
num=number=520#允许多个变量指向同一值,链式赋值
print(num,number)
print(id(num))#id()查看对象内存地址
print(id(number))
a,b=10,20#系列解包赋值
print(a,b)
a,b=b,a#交换
print(a,b)
c,d,e,f,g,h='python'#字符串分解赋值
print(c,d,e,f,g,h)
num0=987#十进制
num1=0b1010101#二进制
num2=0o765#八进制
num3=0x87ABF#十六进制
print(num0)
print(num1)
print(num2)
print(num3)
#浮点型
num4=300.0
num5=3E2
print(num4,num5)
num6=0.1
num7=0.2
print(num6+num7)#不确定尾数不可避免-->round()四舍五入
print(round(num6+num7,1))
#复数
num8=123+456j
print("实数部分:",num8.real)
print("虚数部分:",num8.imag)
print("hello\tworld")
print("helloworld\tbypython")#\t:水平制表位(8个字符),用于横向跳到下一个制表位
print("python print:\'hello word\'")
print("python print:\"hello word\"")
print("hello world\n你好世界")
print(r"hello world\n你好世界")#r取消转义
character0='hello world'
character1='你好世界'
print(character0)
print(character0[2:7])#字符串切片
print(character0[-9:-4])
print(character0[:7])
print(character0[2:])
print(character0[:])
print(character0[0],character0[-11])#字符串索引
print("hello world"[0],"hello world"[-11])
print(character0+character1)#连接字符串
print(character0*10)#拷贝十次
print("hello"in character0)#是否为子集
print("你好"not in character0)#是否不为子集
#多行字符串
character_string0='''hello world
你好世界
by python
来自python'''
print(character_string0)
#布尔类型
boolean0=False
boolean1=True
print(boolean0,boolean1)
print(type(boolean0),type(boolean1))
print(boolean0+10,boolean1+10)
print(False+10,True+10)
print(bool(10),bool(10.0),bool(0),bool(0.0),
bool('hello world'),bool(' '),bool(''),
bool([]),bool({}),bool(()),
bool(None))#python中一起皆对象,每个对象都有bool值
print(True and True)#逻辑与
print(False or False)#逻辑或
print(not True)#逻辑非
x0=99.99
x1=int(x0)#数转整数
x2=float(x1)#数转浮点数
x3=str(x0)#转字符串
x4=chr(x1)#整数转对应ascii字符
x5=ord(x4)#ascii字符转对应整数
x6=hex(x1)#整数转十六进制
x7=oct(x1)#整数转八进制
x8=bin(x1)#整数转二进制
print(x0,x1,x2,x3,x4,x5,x6,x7,x8,'\n',
type(x1),type(x2),type(x3),type(x4),type(x5),type(x6),type(x7),type(x8),)
x9='x0+x1'
print(eval(x9),type(eval(x9)))#eval去掉引号,执行运算;常用与input一起,获取输入值
variable=eval(input('请输入值'))
print(variable,type(variable))
print(12&8)#按位与运算
print(4|8)#按位或
print(31^22)#按位异或
print(~123)#按位取反
print(2<<3)#左移动2位=2*2*2*2
print(16>>3)#右移动2位=8/2/2/2
print(-16>>3)
运行结果