Python Strings and variables

Source: Internet
Author: User

Variable:

1. You must assign a value before using the variable;

2. Variable names can be letters, numbers, underscores, but cannot start with numbers;

3. The letters can be uppercase and lowercase, but the case is different, such as Fishc and Fishc are not the same;

4. The equal sign (=) is the meaning of the assignment, the left is the name behind the value can not be written backwards;

5. Variable name as far as possible to professional. Readability is stronger.

Escape characters:

1. If we want to print let ' s go!

>>>let ' s go!

This will be an error.

Use the following method (use the backslash!) )

>>>let\ ' s go!

You can get "let's go!"

or use double quotes:

>>>print ("Let ' s go!")

Let ' s go!

Original string:

But if you want to print "C:\now"

Method One:

>>>str = ' C:\\now '

>>>print (str)

C:\now

But if you want to print "C:\now\haha\miaomiao\bigeng"

Method:

>>>str = R ' C:\now\haha\miaomiao\bigeng '

>>>print (str)

C:\now\haha\miaomiao\bigeng

But there is one problem: if you want to print "C:\now\haha\miaomiao\bigeng\"

The method above will be error-solving:

>>>str = R ' C:\now\haha\miaomiao\bigeng ' + ' \ \ '

>>>print (str)

C:\now\haha\miaomiao\bigeng\

Long string

If you want to print:

 If I love you--
never learn the birds,
to repeat the monotonous song of the shade,
also not only like the fountain,
perennial send to cool comfort;
also more than Xianfeng, increase your altitude, Foil Your Majesty.
even daylight.
even spring rain. The
workaround is as follows:
>>>str = "" "
   If I love you--  
Never learn the birds of infatuation,
  
also more than just a fountain,
All year round to bring cool comfort;

even daylight.
even spring rain.

to get the expected results.
< strong> Single Double quote:
>>>s6 = ' I realy like "python" !‘  
>>>print (S6)
I realy like "python"!
Again:
>>>S5 = "Let ' s go!"
>>>print (S5)
Let ' s go!

Python Strings and variables

Related Article

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.