Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to analyze Python string

Shulou Source: shulou.com Published: 2022-06-01 17:54:12 10月03日 Update

Today, I will talk to you about how to carry out Python string analysis, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

1.for re-implementation: 1, 2, 3... + 100mm?

Running result:

Python Code:

Click (here) to collapse or open

# use for to compute 1 / 2 / 3 / 3 / 100

Final=0

For i in range (1101):

Final=final+i

Print'1, 2, 3, 1, 2, 3, 1, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 3, 2, 3, 2, 3, 2, 3, 2, 3, print'1, 2, 3, 3, 2, 2, 3, 2, 2, 3, 2, 3, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 2, 3, 2, 2, 3, 2, 2, 3, 2, 2, 2, 3, print', final.

Interpretation:

Range (1,101) means to start at 1 and end at 101 (excluding 101), taking all the integers in it.

Compared to yesterday's while, there is no longer the need for a single variable to record the number of cycles.

-*-

two。 String formatted output

Running result:

Code:

Click (here) to collapse or open

From random import randint

Num=randint (1100)

Print 'Guess what I think?'

Final=False

While final==False:

Answer=input ()

If answernum:

Print str (answer) +'is too bigger'

If answer==num:

Print "Good, you guess it! It's d." answer

Final=True

Two formatting methods:

1) str (): converts numbers to strings

2) format the string with%:

% d replace integers

% f replace decimal places (want to keep two decimal places,% .2f)

% s to replace a string

-*-

Add a basic knowledge: the use of strings

Running result:

Code:

Click (here) to collapse or open

Print 'Method 1, "Yiyi's mom."

Print 'Method 1 is a "good" baby.'

Print 'Method 2 What's your name? "Isimm Yiyi."''

Print 'Method 2 Iris Iris, "And you?"

Print 'Method 3 good I\' Ma\ "baby.'"

Print 'Method 3 is this is\

Same line.'

Knowledge points:

The most common string representations are single quotation marks ('') and double quotation marks (""): 'string' has the same effect as "string"

It must be English characters!

There are odd and double quotation marks in the output, what should I do? See the chestnut, can you see that there are three ways?

Question: what is it used for?

Click (here) to collapse or open

Print 'Well study,\ nwell think,\ nwell listen,\ n\

Well do,\ nwell speak\ n-- come onboarding'

Print'^ _ ^ @ _ @ * _ *'

Results:

The running version of the program:

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32

Type "copyright", "credits" or "license ()" for more information.

After reading the above, do you have any further understanding of how to analyze Python strings? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Characters strings results runs codes contents quotes formats knowledge analysis decimals integers methods outputs variables basics basics commonly used effects numbers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple Shulou Tech Info Linux Huawei