Python user interaction

Source: Internet
Author: User

The python definition string is usually enclosed in single or double quotes, including the content to be represented, such as:

Name   = "Linjunjie" address = ' Taiwan '

If you want to define a string with more than one line, use three single quotes

person = "name=jjjob=geshouage=30" Print (person)
First Interactive program:

Print user-entered content

Name = input ("Name:") Age  = input ("Age:") Job  = input ("job:") info= '-----------info of ' ' +name+ '---------- ----Name: ' +name+ ' ' Age: ' +age+ ' Job: ' +job+ ' ' print ' (info)

"+" means splicing string variables, similar to JS, a string in the middle of the need to splice variables, this representation is too cumbersome, Python has a simpler way:

The second way of replacing:
Name = input ("Name:") Age  = input ("Age:") Job  = input ("job:") info= "-----------info of%s--------------name:% sage:%sjob:%s '% (name,name,age,job) print (info)

%s means that the placeholder represents the replacement of the contents of the following parentheses.

The data type received by%s is a string.

The data type received by%d is an integer. The Python default input is a string, if you want to use%d to convert the input content.

string-To-integer:

Age  = input ("Age:") print (type (age), type (int))) #<class ' str ' > <class ' int ' >

Integer-To-string:

Age  = Int (Input ("Age:")) print (type (age), type (str)) #<class ' int ' > <class ' str ' >
The third Way of replacing:
Name = input ("Name:") Age  = Int (Input ("Age:")) Job  = input ("job:") info= "-----------info of {_name}---------- ----Name:{_name}age:{_age}job:{_job} ". Format (_name=name,           _age=age,           _job=job) print (info)

  

  

  

  

  

Python user interaction

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.