变量
1.直接创建,无需指定类型,自动根据赋值的类型决定变量类型。
days=365
str_test=”china”
int_test=123
float_test=122.5
2.每行代码写完无需分号
3.用_表示名字
number_of_days=365
4.print函数打印
print ‘hello’ print (hello)
print ‘number_of_days’
5.type函数输出变量类型
print(type(str_test))
6.类型转换
str_eight=str(8)
eight=8
str_eight_two=str(eight)
str_eight=”8”
int_eight=int(str_eight)
int_eight=float(str_eight)
7.算术运算
加减乘除+、-、*、/
平方**2
用户交互
读取用户输入,用input读入的都是字符串格式
name=input(“what is your name?”) #wei
print(“hello”,name) #hello wei
print(“hello”+name) #hello wei格式化输出
%s占位符,%连接符
数据类型
基本类型
数字:整型int(32位机(-2^31–2^31-1),64位机(-2^63–2^63-1)),长整型long,浮点型float字符串:文本str,字节bytes,加“ ”的字符被认为是字符串,字符串也能进行加,乘运算。
布尔:true,false
数据集
列表list:
元祖tuple:
字典dict:有序字典,无序字典
集合set:有序集合,无序集合
运算符
- 算数运算:+、-、、*(次幂)、//(整除)、%
- 比较运算:==、!=、>、<、>=、<=
- 赋值运算:=、+=、-=、=、/=、%=、*=、//=
- 逻辑运算:and、or、not