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

How to use the python basic string str

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge about "how to use python basic string str". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

String str:

Definition: An immutable sequence container consisting of a series of characters, storing the encoded values of the event characters

Code:

Byte: The smallest computer storage unit, equal to 8 bits.

2. Character: single number, text and character

3. Character set (code table): store the corresponding relationship between characters and binary sequences

Coding: The process of converting a character into a corresponding binary sequence.

Decoding: The process of converting a binary sequence into a corresponding character

6. Coding mode:

ASCLL code: contains English, numbers and other characters, each character 1 byte

GBK encoding: ASCLL compatible contains 21003 Chinese characters; English 1 byte, Chinese 2 bytes

Unicode: International Uniform Coding, 2 bytes per character in the old character set, 4 bytes in the new character set

UTF-8 encoding: Unicode storage and transmission mode, English 1 byte, Chinese 3 bytes.

= == != "str01 = " Wukong "str02 = " Bajie "#String concatenation str03 = str01 + str02#String accumulation str01 += str02print(str01)#Duplicate element print(str02 * 3)str02 *= 3print(str02)# "

< >

= == != "Compare elements in two containers at once, return comparison results if one is different

member operator

1. Grammar:

data in sequence

data not in sequence

2. Function:

Returns bool type if a value is found in the specified sequence

print("My name is" in "My name is the Great Sage of Heaven")print("My name is" not in "My name is the Great Sage of Heaven") Output result: TrueFalse

index inedx

1. role

access to the container element

2. Grammar:

Container [integer]

3. Description:

The forward index starts at 0 and the second index is 1.

Reverse index starts at-1 and represents the last one

message = "My name is the Great Sage of Heaven"#Get the third word print(message[3])#Get the last word print(message[-1]) Output result Tiansheng

slices slice

1. Function:

Take the corresponding elements from the container and form a new container

2. Grammar:

Container [(Start Index):(End Index):(Step Size)]

3. Description:

The part enclosed in parenthesis () means that it can be omitted

End index does not contain element at this location

Step size is the offset the slice moves after each acquisition of the current element

message = "My name is Great Sage of Heaven"print(message[0:1])#Start value defaults to the beginning print(message(:2))#End value defaults to the end print(message[-2:])print(message[:]) Output result: My name is Great Sage I am Great Sage of Heaven

built-in functions

"Python basic string str how to use" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

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

Development

Wechat

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

12
Report