初识python---简介,简单的for,while&if

一编程语言:编程语言是程序员与计算机沟通的介质;
编程语言的分类:
 1机器语言:是用二进制代码表示的计算机能直接识别和执行的一种机器指令的集合。
          优点:灵活,直接执行和速度快
          缺点:不用机器不能执行
 2汇编语言:实质和机器语言是相同的,是直接对硬件操作,只不对指令采用了英文缩写,标识符更容易识别和记忆。
           优点:可执行文件比较小,执行速度快
           缺点:源程序比较冗长,复杂,容易出错,且需要更多的专业知识。
 3高级语言:以人类的日常语言为基础的一种编程语言,使用一般人易于接受的文字来表示,使程序编写员编写更容易,亦有较高的可读性,以方便对电脑认知较浅的人亦可以大概明白其内容。
         优点:大大简化了程序中的指令,门槛低。
         缺点:需编译。
 
二python:
1.python执行文件过程:
   

 2.文件头:

#!/usr/bin/env python    执行文件的解释器
# -*- coding:utf-8 -*-     

3.注释:

#这是单行注释
'''这是
多行
注释'''

4.执行脚本传入参数:

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

import sys
print sys.argv

5.变量:

   变量名只能是 字母、数字或下划线的任意组合

   变量名的第一个字符不能是数字

   以下关键字不能声明为变量名
   ['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']

6.输入输出:input----3

                raw-input----2

7.简单的运算;

8:流程控制:while for & if

  a.使用while循环输出1 2 3 4 5 6     8 9 10

#!/usr/bin/env python
# -*- coding:utf-8
x = 0
while x <=10:
   x+=1
   if x ==7:
     continue 
   print( x )
  

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

#!/usr/bin/env python
# -*-coding:utf-8 -*-
i=0
s=0
while i <=100:
   if i%2==0:
       s=s-i
   else:
       s=s+i
   i=i+1
print (s)

c.用户登陆(三次机会重试)


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

import getpass
usr = 'mona'
pw = '123'
x = 0

while Ture:
if x=3
print('loin fail')
break
name = input('please input your name:')
passwd = input('please input your password:')
if usr == name and pw == passwd:
print('login successful')
break
else:
print('user or password wrong')
     x = x + 1
 

   

原文地址:https://www.cnblogs.com/mona524/p/6952034.html