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 }}
aabbccgithub
Python24
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Python24
/
00Python
/
day06
/
basic02.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
62 lines (47 loc) · 1.62 KB
master
Breadcrumbs
Python24
/
00Python
/
day06
/
basic02.py
Copy path
Top
File metadata and controls
Code
Blame
62 lines (47 loc) · 1.62 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
python定义函数, 对代码进行封装,python也是引用传递,而不是值传递
1- 如果函数名一样,python并不会报错,而是会覆盖
def 函数名(参数)
"""
def
my_print
():
print
(
"HAHAHHA"
)
def
my_print
():
print
(
"HAHAHHA22222"
)
for
i
in
range
(
5
):
my_print
()
# 如果提示shadows in xxx build in是因为你定义的函数名和内置的函数名一样,比如sum()
def
my_sum
(
a
,
b
):
print
(
"a + b = %d"
%
(
a
+
b
))
my_sum
(
1
,
5
)
# 带有返回值的函数, 使用 -> 的方式,和typescript类似
def
my_sum
(
a
,
b
)
->
int
:
return
(
a
+
b
)
print
(
"a + b = %d"
%
my_sum
(
1
,
5
))
"""
函数的嵌套调用,就是函数中调用另一个函数
1- my_func02 必须定义在My_func01之前,真正调用的时候才会加载,并不会全局预加载
2- 内置函数的作用域,不会自动调用
"""
def
my_func02
():
print
(
"C"
)
print
(
"D"
)
def
my_func01
():
print
(
"A"
)
my_func02
()
print
(
"B"
)
my_func01
()
def
my_func03
():
print
(
"A"
)
# 内置def函数,注意作用域, 注意内置函数不会自动调用
def
my_func04
():
print
(
"C"
)
my_func04
()
print
(
"D"
)
print
(
"B"
)
my_func03
()
# 函数参数的乱序位置,也可以像kotlin一样添加关键字参数
# 注意: 如果某个参数使用了关键字参数,那么之后的参数必须都必须使用关键字参数
# 换句话说,就是参数可以合理的一一对应,开发中一般很少使用关键字参数,看懂即可
def
get_info
(
name
,
age
)
->
str
:
return
"name: %s, age: %s"
%
(
name
,
age
)
print
(
get_info
(
age
=
"26"
,
name
=
"张三"
))
You can’t perform that action at this time.