首页  >  文章  >  后端开发  >  详解Python输入和输出

详解Python输入和输出

高洛峰
高洛峰原创
2017-03-10 18:37:371413浏览

这篇文章介绍详解Python输入和输出

eg:ex1.py

#!/usr/bin/env python

# _*_ coding = utf-8 _*_

import getpass

name = raw_input('please inputyour username:')

pwd = getpass.getpass('inputyour password:')

print 'the name is:',name

print 'the password is:',pwd

执行结果:

[root@localhost~]# python ex1.py

please input yourusername:huwei

input yourpassword:

the name is:huwei

the password is:huwei123

eg:修改的ex1.py

#!/usr/bin/env python

# _*_ coding = utf-8 _*_

import getpass

name = raw_input('please inputyour username:')

pwd = getpass.getpass('inputyour password:')

print 'the name is:',name

print 'the password is:',pwd

if name == 'huwei' and pwd =='huwei123':

 print 'you login successfully!'

执行结果:

[root@localhost~]# python ex1.py

please input yourusername:huwei

input yourpassword:

the name is:huwei

the password is:huwei1234

[root@localhost~]# python ex1.py

please input yourusername:huwei

input yourpassword:

the name is:huwei

the password is:huwei123

you loginsuccessfully!

eg:修改ex1.py

#!/usr/bin/env python

# _*_ coding = utf-8 _*_

import getpass

name = raw_input('please inputyour username:')

pwd = getpass.getpass('inputyour password:')

print 'the name is:',name

print 'the password is:',pwd

if name == 'huwei' and pwd =='huwei123':

 print 'you login successfully!'

else:

 print 'your password is wrong!'

执行结果:

#!/usr/bin/envpython

# _*_ coding =utf-8 _*_

import getpass

name =raw_input('please input your username:')

pwd =getpass.getpass('input your password:')

print 'the nameis:',name

print 'thepassword is:',pwd

if name =='huwei' and pwd == 'huwei123':

 print 'you login successfully!'

以上是详解Python输入和输出的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn