一、Python介绍

发展史:

     被解救的姜戈
     2.4     50万行

      Python 2.6 - October 1, 2008
      Python 2.6.1 - October 1, 2008
      Python 2.6.6 - October 1, 2008
      Python 3.0 - December 3, 2008
      Python 2.7 - July 3, 2010 #目前业内主流使用的工业版本依然是2.7

      print "hello world" #in 2.x
      print("hello world") #in 3.x
In summary : Python 2.x is legacy, Python 3.x is the present and future of the language
总结: python2.x 是遗产, python3.x是现在和未来的语言

     2.x = 默认编码 =ASSIC =不支持
     3.x = 默认编码 =UNICODE =默认支持中文

python 2 vs 3:
     1. 默认支持中文
     2. 不兼容2.x
     3. 核心语法调整,更易学
     4. 新特性默认只在3.x上有

二、系统位数:

     32bit =内存的最大寻址空间是2**32, 4GB
     64bit =2**64 但实际上支持不到这么大的内存,2**4x, 目前主板支持的最大的内存是100多GB
     4GB ==64位系统 会不会比32位系统快? = 一样的

三、硬盘:
     5400转 = 每分钟 =骑自行车
     7200转 = 每分钟 =骑电动车
     10000转 = 每分钟 =骑快速电动车
     15000转 = 每分钟 =骑摩托车 机械硬盘最快的
     SSD = Tesla

四、Python 2 or 3?
     安装
     交互器模式

开始-->cmd --> cd c:\ -->dir
     cd = change directory
     dir = 查看当前目录文件列表
     cd .. 返回上一层目录
     cd ../.. 返回上上一层目录
     cd ../../.. 返回上上上一层目录
     cd ../../../.. 返回上上上上一层目录

     D:\>"d:\Program Files\Python35\python.exe" c:\hello.txt
     Hello World!

#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

环境变量
      D:\Program Files\Python35\Scripts\;
      D:\ProgramFiles\Python35\;
      %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
      D:\Program Files\Python27

五、执行py程序方式为:
       1. 交互器,缺点程序不能永久保存,主要用与简单的语法测试相关
       2. 文件执行

六、Hello World程序
       变量:是为了存储程序运算过程中的一些中间 结果,为了方便日后调用

       print("Hello World!")

       print("Alex")
       print("JinXing")

       name = "Alex Li"
       x = 3
       y = 4

       z = x * y         #运行5分钟 =12

       print("x乘以y=", z )

       print("z=", z )

       z = 5*8
       print("z=", z )

       print = 3 ------是保留字符,print不可使用
       print(print)------是保留字符,print不可使用

 

七、变量的命名规则
      1. 要具有描述性
      2. 变量名只能_,数字,字母组成,不可以是空格或特殊字符(#?<.,¥$*!~)
      3. 不能以中文为变量名
      4. 不能以数字开头
      5. 保留字符是不能被使用
      常量 :不变的量 pie = 3.141592653....
      在py里面所有的变量都是可变的 ,所以用全部大写的变量名来代表次变量为常量
内存何时释放?
示例:students

           student_number=30  #python

           studentNumberPython=30  #驼峰体

           4name=不可以

           nam32e4=可以

以下关键字不能声明为变量名:

            ‘and','as','assert','break','class','continue','del','elif','else','except','exec','finally','for','form',

            'global','if','import','in','is','lambda','not','or','pass','print','raise','return','try','while','with','yield'

八、字符编码
      支持中文的第一张表就叫 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

      print("我爱北京")

      python3.x == unicode默认编码
      unicode 是向下兼容gb2312 , gbk

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

8-1.程序一:

     death_age=80

     name=input("your name:")

     age=input("your age:")  #input    接受的所有数据都是字符串,即便你输入的是数字,但依然会被当成字符串来处理

     print(type(age))

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

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

     print("Your name:",name)

     #print("You can still live for ",death_age-int(age),"years......")

     print("You can still live for "+str(death_age-int(age))+"years......")

8-2.程序二:猜年龄

     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 ...")

8-3.程序三:猜成绩

     score = int(input("score:"))

     if score>90:

  print("A")

 elif score>80:

  print("B")

 elif score>70:

  print("C")

 elif score>50:

  print("D")

 else:

  print("滚")


用户输入

模块初识
     .pyc是个什么鬼?
数据类型初识
      数据运算
表达式if ...else语句
缩进 IndentationError: expected an indented block
IndentationError: unindent does not match any outer indentation level
SyntaxError: invalid syntax 语法错误
tab != 4个空格       缩进级别必须保持一致
 
表达式for 循环
break and continue
表达式while 循环