superfang
及时当勉励,岁月不待人

一 python 变量

  变量命名规则:

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

      2 不能以数字开头

      3 不能是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']

变量的赋值

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
name1 = "zhangsan" 
name2 = "licsi"

 

图解

     7-1430341076

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

name1 = "wupeiqi"
name2 = name1

 

49-979288684

二  初级导入模块

模块导入是大大简化你的程序的可读性。

比如 1.py

复制代码
#!/usr/bin/env python

#_*_coding:utf-8_*_

import 2.py

print("hello")
复制代码

 

而2.py

#!/usr/bin/env python

#_*_coding:utf-8_*_

print("world")

 

 

而执行python 1.py结果是

world

hello

大家看到了吧,import xxx.py 就是将这个文件的内容导入进来替换这个import行。

 

 

 

三 获取用户输入

python 3中只有 input

 

 

输入密码时,如果想要不可见,需要利用getpass 模块中的 getpass方法,即:

复制代码
1 #!/usr/bin/env python
2 # _*_ coding:utf-8 _*_
3 __author__ = 'Administrator'
4 import getpass
5 i1 = input("username:")
6 #i2 = input("passwd:")
7 i2 = getpass.getpass("passwd:")
8 print("username:%s password:%s") % (i1,i2)
复制代码
posted on 2018-03-06 10:37  卡子方  阅读(483)  评论(0)    收藏  举报

levels of contents