Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
gaogan-python
Python24
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Python24
/
00Python
/
day04
/
basic02.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
42 lines (38 loc) · 1.98 KB
master
Breadcrumbs
Python24
/
00Python
/
day04
/
basic02.py
Copy path
Top
File metadata and controls
Code
Blame
42 lines (38 loc) · 1.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
a.ljust(self, width, fillchar) 字符串进行左对齐,字符串占用的长度和需要填充的字符
a.rjust(self, width, fillchar) 字符串进行右对齐,字符串占用的长度和需要填充的字符
a.center(self, width, fillchar) 字符串进行居中,字符串占用的长度和需要填充的字符
a.lstrip(char) 删除字符串左边的字符,不写参数的话去除的是左边空格,相当于左边trim()
a.rstrip(char) 删除字符串右边的字符,不写参数的话去除的是右边空格,相当于右边trim()
a.strip(char) 删除字符串两边的字符,不写参数的话去除的是两边空格,相当于java的trim()
"""
a
=
"abcdef"
print
(
a
.
ljust
(
10
,
"0"
))
# abcdef0000
print
(
a
.
rjust
(
10
,
"0"
))
# 0000abcdef
print
(
a
.
center
(
10
,
"0"
))
# 00abcdef00
print
(
a
.
lstrip
(
"0"
))
print
(
a
.
rstrip
(
"0"
))
print
(
a
.
strip
(
"0"
))
"""
a.partition("b") 将字符串以"b"字幕,分割,如果b在中间且只有一个b,那么返回一个数组[前,"b",后]
a.splitlines() 将字符串逐行分割,返回一个list,非数组,按需求进行选择方法
a.isalpha() 字符串是否全是字母,不论大小写,返回bool
a.isdigit() 字符串是否全是数字,返回bool
a.isalnum() 前两个的集合体al + num,判断字符串是否包含数字或者字母或者混合也行
a.isspace() 字符串是否只包含空格
a.join(["xxx","yyy"]) list中每个元素的后面都插入a字符串
"""
b
=
"ab
\n
cd
\n
ef"
print
(
a
.
partition
(
"b"
)[
1
])
# ('a', 'b', 'cdef') -> b
print
(
b
.
splitlines
())
# ['ab', 'cd', 'ef']
print
(
a
.
isalpha
())
print
(
a
.
isdigit
())
print
(
a
.
isalnum
())
print
(
a
.
isspace
())
print
(
"x"
.
join
([
"1"
,
"2"
,
"3"
]))
# 1x2x3
print
(
""
.
join
([
"1"
,
"2"
,
"3"
]))
# 123 将list迅速转换为一个字符串
# "abcbdbebf" -> "acdef"
c
=
"abcbdbebf"
d
=
c
.
split
(
"b"
)
# 去除字符串中所有的b,返回一个list
result
=
""
.
join
(
d
)
# list转换为字符串
print
(
result
)
You can’t perform that action at this time.