Python's Path (ii) string

Source: Internet
Author: User

We chose to do Python programming under Ubuntu: Create a. py file, which starts with the Python code, and then uses the command $python file name in the shell to display the results of the run.

Here are a couple of string-related functions and syntax:

1. Input

Name = input ("What ' s your name?") Print "Hello," + name + "!"

Input will be in the output "What ' s your name?" Let the user enter, if at this time the user input Tom, will be an error--"Nameerror:name ' Tom is not defined", but the input "Tom" will print "Hello, tom!". This is because input requires the user to enter their name with quotation marks. Obviously this is a bit harsh, so let's look at the following function.


2. Raw_input

Age = Raw_input ("What old is You?")


Entering 21 is correct at this point because Raw_input will take all of the input as raw data and put it into a string.
In general, we use the Raw_input function whenever possible.


3. Escape character ' \ '

Print "Hello, world!"

Will print Hello, world! Also, we can use it on an expression:

1 + 2 + 4 + 5

Results are printed in 12.


4. repr

This function preserves the original form of the input, and for an example, it's clear.



If you use print only, it will replace the quotation marks of the string and the long integer L,REPR will retain these characteristics.



Python's Path (ii) string

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.