# -*- coding:utf-8 -*-#用户输入 && formatted output #getpass module is built-in, you can hide the input contents of the Import getpassusername = input ("username:") password = input ("Password:") age = int (Input ("Age:")) Job = input ("Job:") #print (type (age), type (str)) Print variable type #password = getpass.getpass (Input ("Password:")) info = "---- info of %s ----username = %spassword = %sage = %sjob = %s ' % (Username,username, Password,age,job) print (info) info1 = "---- info of {0} ----username = {0}password = {1}age = {2}job   = {3} " .format (username,password,age,job) print (INFO1) info2 = " ""---- info of {_name} ----username = {_name}password = {_passwd}age &nBsp;= {_age}job = {_job} "" " .format (_name=username, _passwd=password, _age=age, _job=job) Print (Info2) # # #说明, Python 2.x zhong de raw_input () Same as input () effect in python 3.x python2.x input () is variable name # #, print (type (variable)) Print Variable Type # #, the default type is a string (string) str---> Integer with age = int (input ("variable")) #4, ' ' * ' has two meanings, respectively, for multiline comments and multiline print # #,%s placeholder for string %d to represent integer %f for floating point, fractional Formatted output has the following three implementations, in which it is recommended to use [Info2] in # #, [info]%s to represent string placeholders, the number of rows assigned to the corresponding  [INFO1] {0} in the order of variables, [Info2] introduced The corresponding relationship between the parameters of _name and other variables
This article is from the "Dr Small White" blog, please be sure to keep this source http://metis.blog.51cto.com/1203503/1953657
Python 3 user input and formatted output