Python Learning Note "04" user input

Source: Internet
Author: User

   user Input
1 name = input ("username:")2 password = input ("  Password:")34print(name, password)

  Other example 1: string concatenation

1Name = input ("Name:")2Age = Input ("age :")3Job = input ("Job:")4Salary = input ("Salary:")5 6 7info =" "8 ----------info of" "+ name +" " ----------9 Name:" "+ name +" "Ten age :" "+ Age +" " one Job:" "+ Job +" " a Salary:" "+ Salary +" " - " " -  the Print(info)

  Additional example 2: using placeholders

1Name = input ("Name:")2Age = Input ("age :")3Job = input ("Job:")4Salary = input ("Salary:")5 6info =" "7 ----------info of%s----------8 Name:%s9 age :%sTen Job:%s one Salary:%s a " "%(name, name, age, job, Salary) -  - Print(info)

The string is%s; integer%d; Floating point%f

  Print data type

1 age = input ('age:')2print(type (age))

  Cast data type

1 age = int (input ("age:"#integer2print( Type (age), type (str))

  Other Example 3

1Name = input ("Name:")2Age = Input ("age :")3Job = input ("Job:")4Salary = input ("Salary:")5 6info =" "7 ----------info of {_name}----------8 Name: {_name}9 age : {_age}Ten Job: {_job} one Salary: {_salary} a " ". Format (_name=name, -_age=age , -_job=name, the_salary=Salary) -  - Print(info)

  Other Example 4

1Name = input ("Name:")2Age = Input ("age :")3Job = input ("Job:")4Salary = input ("Salary:")5 6info =" "7 ----------info of {0}----------8 Name: {0}9 age : {1}Ten Job: {2} one Salary: {3} a " ". Format (name, age, job, Salary) -  - Print(info)

  Ciphertext input Password

1 Import Getpass 2 3 name = input ("username:")4 password = getpass.getpass ("  password:")56print(name, password)

Python Learning Note "04" user input

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.