Python之路,Day4 - Python基础-用户交互程序

本节内容

  1. 用户交互程序

一、用户输入 

1
2
3
4
5
6
7
#!/usr/bin/env python
#_*_coding:utf-8_*_
 
 
#name = raw_input("What is your name?") #only on python 2.x
name  =  input ( "What is your name?" )
print ( "Hello "  +  name )

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

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env python
# -*- coding: utf-8 -*-
  
import  getpass
  
# 将用户输入的内容赋值给 name 变量
pwd  =  getpass.getpass( "请输入密码:" )
  
# 打印输入的内容
print (pwd)

举例子,将输入的内容打印出来(三种方式):



猜你喜欢

转载自blog.csdn.net/sj349781478/article/details/80964875