How to use str in Python with zero basic knowledge

步履不停
Release: 2019-07-02 15:32:51
Original
3281 people have browsed it

How to use str in Python with zero basic knowledge

Tools/Materials

python3.1.6

pycharm

Methods/Steps

# For strings: Insert a certain string into the middle of all the characters in the following string and concatenate it into a new string. s = '**'.join('good123')print(s)

How to use str in Python with zero basic knowledge

print('****************** Slice**********************')s = 'good_make_dog_love_pig'c = s[-1] # Query the corresponding character according to the subscript, if you count from the left, start from 0 start. If counting from the right, start from -1. print(c)

How to use str in Python with zero basic knowledge

# s[x:y:z] Starting from the x-th character, query to the y-th character (excluding y), z is the step long, the default step size is 1. s = 'good_make_dog_love_pig'res = s[0:10:2]print(res, type(res))

How to use str in Python with zero basic knowledge

s = 'good_make_dog_love_pig'# s[x:y :z] Starting from the x-th character, query to the y-th character (excluding y), z is the step size, and the default step size is 1. res = s[0:10:2]print(res, type(res))

How to use str in Python with zero basic knowledge

res = s[-1::-1] # The step size is a negative number , which means querying from right to left print(res, type(res))

How to use str in Python with zero basic knowledge

print('************Encoding**** *********')a = ord('a') # Query the ASCII code of a certain character pair print(a, type(a))

How to use str in Python with zero basic knowledge

c = chr(97) # Query the corresponding character (ASCII) according to the encoding print(c)c = 'h'print(chr(ord(c) 1))print('Given 2 lowercase letters, a

How to use str in Python with zero basic knowledge

END

Notes

The seventh step is to introduce the random module, otherwise an error will be reported.

Related tutorial recommendations: Python video tutorial

The above is the detailed content of How to use str in Python with zero basic knowledge. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!