open是内件的一个函数,可以帮助我们读写。
变量:
变量不用提前声明,每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。
变量一般由字母、数字、下划线组成;通常第一个字符是字母或下划线“_”;区分大小写。
缩进量要一致
固定语法:
多行注释:选择要注释的行,按住ctrl+问号键:
撤销同上。
多行缩进:选择,按tab键
取消缩进:shift+tab键
open是内件的一个函数,可以帮助我们读写。
变量:
变量不用提前声明,每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。
变量一般由字母、数字、下划线组成;通常第一个字符是字母或下划线“_”;区分大小写。
缩进量要一致
固定语法:
多行注释:选择要注释的行,按住ctrl+问号键:
撤销同上。
多行缩进:选择,按tab键
取消缩进:shift+tab键
ctrl+?
xuanzhong,tab
shift+tab
open(路径+文件名,读写方式)
string='hello world'
f = open('hello world.txt','w')
f . write(string)
f . close()
变量不需要声明,严格缩进,不要乱加
机器学习 = ['决策树','神经网络']
for i in 机器学习:
print (i)
print (i)
Python固定语法
机器学习=['决策树','神经网络','聚类分析']
for 算法 in 机器学习:
print(算法)
string='hello world'
f = open('hello world.txt','w')
f . write(string)
f . close()
Python 3源码文件以
构建字符串:string ='hello world'
打开一个文件:f=open('hello world,txt','w')
查看函数功能(ctrl+点击函数)或者点击函数即可了解函数解释
往文件写入东西:f.write(string)
关文件:f.close()
变量不需提前声明,
string = 'hello world'
f = open('hello world.txt','w')
f.write(string)
f.close()
缩进 tab
两行同一缩进,
多行注释,ctrl+?
shift +tab
1、创建环境时,一定要注意解释器 2、创建新文件,在工程文件夹下建立python文件,生成.py文件,进行程序编程 print(‘helloworld’) str='helloworld' f = open('day1_test1.txt','w') f.write(str) f.close
3、run后,下方出现两句:
C:\Users\Administrator\Anaconda3\python.exe
调用解释器,设置工程时关联好的
D:/TensorFlow_Test/day1_ex1/day1.py
编辑python文件
4、变量不需要提前说明
还能
string = 'hello world'
f = open ('hello world.txt','w')
f.write(string)
f.close()
机器学习=['决策树','神经网络']
for i in 机器学习:
print(i)
string='hello world' f=open('hello world.txt','w') f.write(string) f.close() 机器学习 = ['决策树','神经网络'] for i in 机器学习: print(i) print(i)