初识 python

一、第一句python代码

#!use/bin/env pythom
# -*- conding:utf-8 -*-
#听老师的上面不用管是什么  记住必须要有就行
#如果没有将不能在代码中出现中文

#hello world
print("hello world")  #python 2.x
print "hello world"    #python 3.x

 二、打印用户输入的账号和密码

#!use/bin/env pythom
# -*- conding:utf-8 -*-

import getpass
name = input("请输入用户名:")
# mima = input("请输入密码:")
mima = getpass._raw_input("输入密码:")  #使输入不可见  python 3.x
#mima = getpass.getpass("输入密码:")    #python 2.x  变*号也暂时不知道
print(name)
print(mima)

三、关于变量

name = "456"
#name 为变量名
#变量名由  数字 字母 下划线组成
#            不能由数字开头
#            不能是pytho内部关键字

四、条件语句

#!use/bin/env pythom
# -*- conding:utf-8 -*-

if 1 > 5:
    print("1 > 5")
elif 1 == 5:
    print("1 = 5")
else:
    print("1 < 5")

 五、while循环

#!use/bin/env pythom
# -*- conding:utf-8 -*-

import time

f1 = True
while f1:
    print("1")
    time.sleep(1)  #延迟1秒
    # f1 = False
print("end")
set = True
while set:
    print("1")
    break #用于跳出当前循环,break 后边代码将不再执行
    #continue 用于跳出本次循环,继续下次循环(后面的代码同样不再执行)
print("end")
   break 与 continue
#!use/bin/env pythom
# -*- conding:utf-8 -*-
set = 1
while True:
    if set == 7:
        set += 1
        continue
    print(set)
    set += 1
    if set == 10:
        break
print("end")
  输出:1,2,3,4,5,6,8,9

 

posted @ 2017-01-04 17:12  getpoint  阅读(510)  评论(0)    收藏  举报