基础即常识。
- Python的对象模型
- Python中一切皆对象。
- 内置对象:数字,字符串,列表,元组,集合等等。
- 基本输入
- 基本模式 变量 = input("提示字符串")
- 其中变量和提示字符串可以省略
- input函数将用户输入内容以字符串返回。
- 代码
1 a = input("i亲输入数据:") #输入 2 print(a) # 打印输入的内容 3 print(type(a)) # 查看a的数据类型,即input的返回类型
- 基本的输出
- 基本模式: print([obj1,...][,sep=‘ ‘][,end=" \n"][,file=sys.stdout])
- 省略参数,print()函数所有参数都可以省略,输出一个空行。
print()#输出空行
- 输出一个或多个对象
print(123) #输出一个对象 print(123, ‘abc‘,"python", "ss")#输出多个对象 # 结果默认用空格隔开
- 输出分隔符
- 默认分隔符为空格,可以使用sep参数来指定特殊符号作为分隔符
print(123, ‘abc‘,"python", "ss", sep="**") # 输出 # 123**abc**python**ss
- 输出结尾符号
- 默认以回车换行符作为结尾符号。用end参数指定输出结尾符号。
print("ten") print(100) print("ten",end="=") print(100) /* ten 100 ten=100 */
- 输出文件:使用file参数指定输出到特定文件
file1 = open(‘data.txt‘, ‘w‘) # 打开文件‘data.txt‘(没有则自动创建), ‘w‘写入格式 print(123,"abc",89,"python",file=file1) #用file参数指定输出到文件 file1.close() # 文件打开后必须关闭 print(open(‘date.txt‘.read()) # 输出从文件中读出的内容,read()为open()的读函数
- 程序基本结构
- 缩进:Python使用缩进(空格)来表示代码块。通常末尾的冒号表示代码块的开始。
- 注释
- 注释写法
- 横注释: 以 # 开头,可以单独行,也可以在某行代码后面,#后面的代码不会被执行
- 块注释: 好几行代码或者内容。以三个连续单引号或者双引号开始和结束,中间任何内容机器都忽略掉
- 续行
- 使用"\"符号
if i<144 and x>55: y = x-5 else: y = 0
- 使用括号()
print(‘abc‘,123, ‘aaa‘,354)
- 分隔:使用分号 ; 分隔语句
- 关键字:使用help("keywords")查看系统关键字。
1 /* 2 Here is a list of the Python keywords. Enter any keyword to get more help. 3 4 False def if raise 5 None del import return 6 True elif in try 7 and else is while 8 as except lambda with 9 assert finally nonlocal yield 10 break for not 11 class from or 12 continue global pass 13 14 */
原文:https://www.cnblogs.com/cmn-note/p/10620515.html