python 随记--计算机编程语言

计算机编程语言 

高阶语言:{python ,java,c++, c#,PHP 等}      ----》字节码          虚拟机执行字节码并转换成机器码再后在处理器上执行

低阶语言:{c ,汇编}                                      ----》机器码         机器码在处理器上直接执行,每一条指令控制CPU工作

 

1)语言之间的对比:

                PHP:适用于网页开发,有一定的局限性

                python ,java ,c++等    既适用于网页开发,又可以做后台开发,适用范围相对广泛。

           a) python 与jaxa 的简单对比

               python :开发效率高,执行效率低

               java     :开发效率低,执行效率高

所以,Python和其他语言没有什么本质区别,区别在于:擅长的领域不同。

2)python 的种类

 

  • Cpython     Python的官方版本,使用C语言实现,使用最为广泛,CPython实现会将源文件(py文件)转换成字节码文件(pyc文件),然后运行在Python虚拟机上。
  • Jyhton     Python的Java实现,Jython会将Python代码动态编译成Java字节码,然后在JVM上运行。
  • IronPython     Python的C#实现,IronPython将Python代码编译成C#字节码,然后在CLR上运行。(与Jython类似)
  • PyPy(特殊)     Python实现的Python,将Python的字节码字节码再编译成机器码。
  • RubyPython、Brython ...

3)python 入门

 

print(“hello, world”)


解释器路径:

#!/usr/bin/env python


编码

python解释器在加载 .py 文件中的代码时,会对内容进行编码(默认ascill)

# -*- coding:utf-8 -*-
#!/usr/bin/env python

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

  

print "你好,世界" 

在python2与python3中

python2的默认编码为{ascill}

python3的默认编码为{Unicode}    支持中文

4)、注释

  当行注视:# 被注释内容

  多行注释:""" 被注释内容 """

5)用户输入

name = "jack"
passwd ="abc123"
count =0
while count <3:
    m = input ("请输入用户:")
    n =input ("请输入密码:")
    if m == name and n == passwd:
      print("欢迎登陆")

    else:
        print("输入错误:")
        count =count +1
else:
      print("you have tried too many times .")


6)变量

变量定义的规则:

  • 变量名只能是 字母、数字或下划线的任意组合
  • 变量名的第一个字符不能是数字
  • 不可以用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']

name  ="jack"
n   ="123"

 

7  )数据运算

x = "hello"
y ="world"
print(x)
print(y)
a =x+y
print(a)
x = "hello,world"
print(x)
a=x*1
print(a)
n1 = 5
n2 = 2

n = n1 + n2          #加
print(n)
n = n1 - n2          #减
print(n)
n = n1 * n2          #乘
print(n)
n = n1 / n2          #除
print(n)
n3 = n1 % n2         #余数
print(n)
n = n1 ** n2         #次方
print(n)

 

 

8)、while循环

 

1、使用while循环

输入 1 2 3 4 5 6     8 9 10

count =1
while count <11:
    if count ==7:
        pass
    else :
        print(count)
    count = count +1

2、求1-100的所有数的和

count =1
n =0
while count <101:
    count = count +1
    n = n +count
    print(n)

3、输出 1-100 内的所有奇数  的和

count =1
n =0
while count <100:
    m = count %2
    if m ==0:
        pass
    else :
        n = n + count
    count = count +1
    print(n)

 

 

4、输出 1-100 内的所有偶数    的和

 

count =1
n =0
while count <100:
    m = count %2
    if m ==0:
        n = n + count
    count = count +1
    print(n)

5、求1-2+3-4+5 ... 99的所有数的和

 

count =1
n =0
while count <100:
    m = count %2
    if m ==0:
        n =n-count        
    else :
        n = n + count
    count = count +1
    print(n)

 

 

         

 

posted @ 2017-08-29 09:27  漫路  阅读(260)  评论(0)    收藏  举报