Python 3 user input and formatted output

Source: Internet
Author: User

# -*- 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.