Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
python-study/01python-base/Function.py at master · nebofeng/python-study · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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 }}
nebofeng
python-study
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
python-study
/
01python-base
/
Function.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
97 lines (70 loc) · 2.29 KB
master
Breadcrumbs
python-study
/
01python-base
/
Function.py
Copy path
Top
File metadata and controls
Code
Blame
97 lines (70 loc) · 2.29 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#coding=utf-8
def
printme
(
parameters
):
"打印传递进函数的字符串"
print
(
parameters
)
return
printme
(
"Hello Python !"
)
# python 中,strings, tuples, 和 numbers 是不可更改的对象,而 list,dict 等则是可以修改的对象。
# 不可变类型:类似 c++ 的值传递,如 整数、字符串、元组。如fun(a),传递的只是a的值,没有影响a对象本身。
# 比如在 fun(a)内部修改 a 的值,只是修改另一个复制的对象,不会影响 a 本身。
#
# 可变类型:类似 c++ 的引用传递,如 列表,字典。如 fun(la),则是将 la 真正的传过去,修改后fun外部的la也会受影响
def
ChangeInt
(
a
):
a
=
10
b
=
2
ChangeInt
(
b
)
print
(
b
)
# 结果是 2
# 可写函数说明
def
changeme
(
mylist
):
"修改传入的列表"
mylist
.
append
([
1
,
2
,
3
,
4
]);
print
(
"函数内取值: "
,
mylist
)
return
# 调用changeme函数
mylist
=
[
10
,
20
,
30
];
changeme
(
mylist
);
print
(
"函数外取值: "
,
mylist
)
#参数 : 必备参数 , 关键字参数 , 默认参数 , 不定长 参数
#必备参数, 需要传递参数进去函数
# 关键字参数 。传递参数的时候 。形如 : str="" 参数名,参数值一起传入 。
printme
(
parameters
=
"sss"
)
#如果是多个参数。顺序可以随意
#缺省参数 (默认参数)没传递age的时候有默认值
def
function
(
name
,
age
=
35
):
print
(
name
,
age
)
return
;
# 不定长参数 加了 *的变量名字会存放所有未命名的变量参数
def
printinfo
(
arg1
,
*
vartuple
):
"打印任何传入的参数"
print
(
"输出: "
)
print
(
arg1
)
for
var
in
vartuple
:
print
(
var
)
return
;
a
=
1
def
func
():
a
=
2
print
(
'函数内部的a是:'
,
a
)
func
()
print
(
'函数外部的a是:'
,
a
)
def
func1
():
global
a
a
=
2
print
(
'函数内部的a是:'
,
a
)
func1
()
print
(
'函数外部的a是:'
,
a
)
import
copy
mylist
=
[
1
,
2
,
3
]
def
func3
(
obj
):
obj
=
[
'a'
,
'b'
,
'c'
]
print
(
'inside a is:'
,
obj
)
def
func2
(
obj
):
obj
=
copy
.
deepcopy
(
obj
)
obj
=
[
'a'
,
'b'
,
'c'
]
#我们把这个列表 深拷贝给了 obj
print
(
'inside a is:'
,
obj
)
func3
(
mylist
)
#传参
print
(
'外部的a修改完成后是:'
,
mylist
)
print
(
'------------------'
)
mylist
=
[
1
,
2
,
3
]
func2
(
mylist
)
#传参
print
(
'外部的a修改完成后是:'
,
mylist
)
You can’t perform that action at this time.