Python学习_基本介绍

#!/usr/bin/env python [指定python解释器,env环境兼容(存在多个python版本的情况,加上env会更好)]

which python [查找python解释器的位置]
# -*- coding: utf-8 -*- [指定解释器编译时的编码]
./hello.py
单行注视:# 被注释内容
多行注释:""" 被注释内容 """
import lib
执行Python代码时,如果导入了其他的.py文件,那么执行过程中会自动生成一个与其同名的.pyc 文件,
该文件就是Python解释器编译之后产生的字节码(优先寻找字节码文件)。
ps:代码经过编译可以产生字节码;字节码通过反编译也可以得到代码。

1、创建xxx.py文件
ps:不要有中文路径

2、写代码
a.头部两行特殊代码
b.写功能代码

3、执行代码
a.打开终端
b.python 代码文件的路径

变量定义的规则:
变量名只能是 字母、数字或下划线的任意组合
变量名的第一个字符不能是数字
以下关键字不能声明为变量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def',
'del', 'elif', 'else', 'except', 'exec', 'finally', 'for',
'from', 'global', 'if', 'import', 'in', 'is', 'lambda',
'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

break:用于跳出循环,并且break后面的代码不再执行
continue:用于跳出本次循环,继续下一次循环

Pycharm
1.模板
file => settings => Editor => file and code templates => python script => 右上方
#!/usr/bin/env python
# -*- coding:uft-8 -*-
OK

2.文字大小
file => settings => Editor => color and font => 16

3.运行
a.点击要运行的文件,右键 run
b. view => toolbar
选中要执行的文件
点击>运行
c.在当前文件的空白处,右键run

4.切换py版本
file => settings => project interpreter => 选择版本

基本数据类型
1.整数 int
2.字符串 str
3.布尔值 bool
4.列表 list
5.元祖 tuple
6.字典 dict

posted @ 2019-03-21 14:42  錦衣夜行  阅读(103)  评论(0编辑  收藏  举报