python3学习笔记一

1、交互模式指令

开始--cmd --> cd c:\  -->dir

cd = change directory

dir = 查看当前目录文件列表

 

 

cd .. 返回上一层目录

cd ../.. 返回上上一层目录

cd ../../.. 返回上上上一层目录

cd ../../../.. 返回上上上上一层目录

如果我们要切换盘符的目录,正确的用法是在cd 和路径中间 增加一个“/d”,如cd /d d:

2#c:\hello.txt   .txt 代表文件的扩展名(后缀名),用于区分文件类型

.txt 记事本文本文件

.doc word文件

.xls excel文件

.ppt PPT文件

.exe 可执行文件

.jpg .png  .jpeg  图片

.gif 动态图片

.pdf PDF文件

.mp4 .avi 视频

.py   python文件

.java java 文件

.c .h  c源码

.php php文件

.js   javascript

 

3、设置环境变量

 

 

在其中加入python的路径     D:\python\Scripts\;D:\python\;

 

4、执行py程序方式为:

1. 交互器,缺点程序不能永久保存,主要用与简单的语法测试相关

2. 文件执行

5hello world程序

print("hello world!")

变量

变量是为了存储程序运算过程中一些结果,为了方便日后调用

 

变量的命名规则

1. 要具有描述性

2. 变量名只能_,数字,字母组成,不可以是空格或特殊字符(#?<.,¥$*!~)

studentNumberPhthon(驼峰体)

3. 不能以中文为变量名

4. 不能以数字开头

5. 保留字符是不能被使用

 

常量 :不变的量 pie = 3.141592653....

py里面所有的变量都是可变的 ,所以用全部大写的变量名来代表变量为常量

 

 

6、字符编码

支持中文的第一张表就叫 GB2312

 

1980 gb2312 6700+

1995 gbk1.0 20000

2000 gb18030 27000

big5 台湾

unicode 万国码  支持所有国家和地区的编码

2**16 = 65535 = 存一个字符 统一占用2个字节

 

UTF-8 = unicode 的扩展集,可变长的字符编码集

字符编码发展史

Assic -->Gb2312 ->gbk1.0-->gb18030

Assic -->unicode -->utf-8   /utf-16

 

 

Python2.x == Assic 默认编码

#!-*- coding:utf-8 -*-

#coding:utf-8

 

python3.x == unicode默认编码

 

 

unicode 是向下兼容gb2312 , gbk

 

7、注释

注释

单行注释 #

多行注释用三个单引号或三个双引号 '''被注释的内容'''

8、用户输入

Input接受的所有数据都是字符串,几遍你输入的是数字,但依然会被当成字符串来处理

Int    integer=整数    把字符串转成int,用int(被转的数据)

Str    string=字符串   把数据转成字符串用str(被转的数据)

 

表达式if ...else语句

 

 

age_of_princal = 56

 


guess_age = int(input(">>:"))

 

'''
if guess_age == age_of_princal then
print("yes")

 

else print("no")
'''

 

if guess_age == age_of_princal:
print("yes,you got it..")
elif guess_age > age_of_princal:
print("shoud try samller..")


else:
print("try bigger..")

 

缩进错误 IndentationError: expected an indented block

                            ^

IndentationError: unindent does not match any outer indentation level

SyntaxError: invalid syntax 语法错误

tab !=(不等于) 4个空格

 

缩进级别必须保持一致

posted @ 2020-01-14 11:02  安安369  阅读(123)  评论(0)    收藏  举报