Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The use of string in Python

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "the use of strings in Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Code implementation

# =

# string (str)

S = 'hello'

Print (s)

S = "hello"

Print (s)

# s = "Confucius said," learn and learn it from time to time. Be happy! "

S = 'Master said,' learn and learn it from time to time. Be happy!'

Print (s)

S = 'farmers work hard to hoe at noon,\

Drops of sweat fell into the soil under Wo Xia.

Who knows the meal on the plate?

Every grain is the hard work of the farmers.

Print (s)

S =''the farmers work hard to hoe and harvest at noon

Sweat drips into the soil under Wo Xia

Each bowl of rice, who knows,

Every grain is the hard work of the farmers.

Print (s)

S = "Confucius said:\" learn it and learn it from time to time.\ nHappy! \ "

Print (s)

S ='\ u2250'

Print (s)

Code run output:

Hello

Hello

The Master said, "learn and learn it from time to time, and be happy!"

Farmers work hard to hoe and harvest at noon, sweat drops fall into the soil under he, who knows the rice in the plate, every grain is the hard work of the farmers.

At noon they weed with hoes,

Sweat drips into the soil under Wo Xia

Each bowl of rice, who knows,

Every single grain is the fruit of hard work

The Master said, "learn and learn from time to time.\ nHappy!"

Program analysis

# string is used to represent a piece of text information. The string is the most frequently used data type in the program # in Python, the string needs to be enclosed in quotation marks # s = abc # the string must be enclosed in quotation marks, not the string # quotation marks can be double quotation marks or single quotation marks But be careful not to mix quotes with # s = 'hello' cannot be mixed with SyntaxError: EOL while scanning string literal# cannot be nested between the same quotes # long strings # single and double quotes cannot be used across lines # use triple quotes to indicate a long string''"" # triple quotes can be wrapped And the format # escape character # can be used as an escape character in the string. By escaping characters, you can use some special content in the string # example: #\ 'for' #\ "for" #\ t "for tab #\ n for newline character #\ for backslash #\ uxxxx for Unicode encoding

This is the end of "the use of strings in Python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report