python个人的总结
1.输入
input()
2.输出 数字 字符串 表达式 到文件中
print()
输出到文件中 注意点 1. 所指的盘符一定存在 2 使用file =fp = open(“D:/1.txt”, “a+”)
a+ 如果文件不错在 则创建
存在 就在 文件内容后面继续追加 使用 , 则在一行输出
print(“hello world”, file=fp)
fp.close()
print(520)
输入函数 :
name = input(“请输入一个名字:”)
print(“hello:”, name)
print(1024 * 768)
num1 =input(“请输入一个整数1”)
num2 =input(“请输入第二个整数2”)
print(type(num1),type(num2))
print(int(num1) +int(num2))
转义字符有 \n 换行 \t 四个空格位置
\r 回车 覆盖 \b 回退 r 原字符 ord chr
print(“hello\nworld”)
print("hello\tworld ")
print("hello\rworld ")
print("hello\bworld ")
print(r"hello\bworld ")
print(ord(“乘”))
print(chr(0b010001))
数据类型(6个): number(数字) , 字符串(string), 元组(tuple) , 列表(list), 字典(dictionary), 集合(set)
1 .number(4个):
整数 : int 表示整数 (正数 负数 0 ) 二进制 : 0b 八进制 : 0o 十六进制: 0x
浮点数: float 整数部分 和小数 部分组成
复数型: 3+ 4i
布尔型: True—> 1 or Flase----->0 bool
-
string
字符串: ’ ’ or " " or ‘’’ ‘’’ 不可变得字符序列 -
tuple ()
元组 : tuple (1,2,3),(‘physice’,‘chemistry’), 但是tuple一旦初始化就不能修改 -
list []
列表: list 有序 列表的大小可变 [] list是一种有序的集合,可以随时添加和删除其中的元素。
5.dictionary {}
字典: dictionary 无序 键值对 { }
- set {}
集合: set 无序 {“tom”,“ojb”} 其中元素不能相同
也是一组key的集合,但不存储value。由于key不能重复,所以,在set中,没有重复的key。
变量: 字母 数字 下划线
第一个字符不能是数字
关键字不能声明变量名
注释: # ‘’’ ‘’’ #coding :gbk
数据类型转换:
str() 转化成字符串
int() 转化成整数
float()转化成 浮点型