01Python Basic _ 04 input/output mode, 01python_04

Source: Internet
Author: User

01Python Basic _ 04 input/output mode, 01python_04

1. input ('str ')

1 # coding = UTF-8 2 # Get user information and output 3 4 name = input ('name: ') 5 age = int (input ('Age :')) # input the default string 6 job = input ('job: ') 7 8 info = ''' 9 name: % s10 age: % d11 occupation: % s12 ''' % (name, age, job) 13 14 info2 = ''' 15 name: {_ name} 16 age: {_ age} 17 job: {_ job} 18 '''. format (_ name = name, _ age = age, _ job = job) 19 20 info3 = '''21 name: {2} 22 age: {1} 23 job: {0} 24 '''. format (name, age, job) 25 print (info) 26 print (info2) 27 print (info3)

Note: The data type obtained by input () is 'str'

2. Obtain the entered password

1 # determine whether the user's comfortable user name and password are correct 2 3 import getpass 4 5 _ username = 'hangfei' 6 _ password = '000000' 7 8 username = input ('username: ') 9 password = getpass. getpass ('password: ') # obtain the password with the password 10 if username = _ username and password = _ password: 11 print ('Welcome user {name} login... '. format (name = username) 12 else: 13 print ('invalidusername or password ')

 

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.