การส่งผ่านค่าแบบ Reference และ Value ในภาษา Python (Pass ...
Worksheet 7?????????????????????????????????????????????????????????????????????????????????? Python ??????????????????? ????????????????????????? sum(a,b) ?????????????????????? 2 ??????????????? 1 ?????????????????????????????????????????????????????? ???? ????????????????????????????? 7 ??????????????????????????????????????????? sum() ??????? return ???????? ???????????????????????????????????????????????????????? 2 ?????????????????????????????? 9 ??????????????????????? result ???????????????? return ???????????????? sum() ????????????????????? return ????????????? sum() ??????????????????????? ???????????????????????????? avgNmax(a,b,c) ?????????????????????????????? ???????????????????????????? ???????? return ?????????????????????????? ?????????????????????????????????????? ???????????????????????????? avg_list(num_list) ???????????????????????????? list ????????????????? (integer) ???????????????????????? ????????????????????????????????? ????????????????????????????????????????????????????? Reference ??? Value ?????? Python (Pass by Reference vs. Pass by Value)??????????????????????????????????????????????? 1) Pass by Reference ??? 2) Pass by Value ?????? Python ??????????????? 1 (???????????????????????????????????????) ?????????????????????????? Pass by Reference ????????????????????????????????????????? ?????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????? ????????????????? 2 ???????????????????????????????????? (???????????????????????????????????????????? ?????????????????????????????????????????????? ?????????????????????????? Mutable ???? Immutable?????????????????????????????????????????????????????????????????????????????????????? chagelist() ??? changelist2() ???????????????????????? 5 ???????? list ?????????????????????????????? 6 ???????? list ??? code ???????????????? mylist ?????????????????????????? 1,2,3 ??? 4 ????????? 13 ?????????????, print(mylist) ???????????????????????? list ??? [1,2,3,4] ???????? ??????????????????????????? changelist2() ?????????????? mylist ???????????????? (???? Pass by Reference) ????????????????????????????????????? mylist ??????????? mylist ?????? ??????????? 8 changelist2(mylist) ?????????????????? changelist(mylist) ?????????? chagelist() ???????????????? 5 ?????????????????????????? print(mylist) ??????????? [1,2,3,4,5] ??????????????? ?????????????????????????????????????????? 9 ??????????????? 6 ???????? mylist ????????????? mylist ???????? ??????????? [1,2,3,4,5,6] ???????????????????????? ll print(mylist) again ????????? 15 ????????????? mylist ???????????? 4 ???????????????????????????? object ???? (?????????????????????) ?????????? ?????????????????????????????????????????????????????????? ??????????????????????????????? ????????????????????????????????????? ?????????????? ??????????????????????? 10 ?????????????? mylist ?????????????? [10,20,30] ??????????? print(mylist) ???????? 11 ?????????????????? ?????? [10,20,30] ??????????????????????????? mylist (????????????????????????? 1) ??????????????? ??????????????????????????????????????????????? ???????????????????????????????????????? ????????????????????????????????????????????????? ???????????????????????????????????????? return ???????????????????????????? 12 ?????????????? 15 ??????????????????? mylist ??????????????????? ?????????????????????????? ?????????????????????????? m ???? (myword) ????????????????????????? ???????????????????????? count ?????????????????????? 0 ??????????????????????????? ?????????????????????? ????? _______________________________________??????????? Python code ???????? ???????????????????????????????????????????? (???????????????????????? yes ???? no) ___________________argument ?? function ask_ok() ???????????????????????????????????????????????????????? ___________???????????????????? arguments ????????????? _________??????????????????????????????????????????????????? ????????????????? argument ????????????????????????????????????????????????????????? ????????????????????????? yes ???? no ??????????? ask_ok('OK?to?overwrite?the?file?',?2)????????????????????????? _____________________________________________________________?????????ask_ok('OK?to?overwrite?the?file?',?2,?'Come?on,?only?yes?or?no!')??????????????????????????????????????? 4 ___________________________________________________________???????????????????????????? replacevowel(input_str, v) ???????????????????? string ???? input_str ????????? v ????????????????????????????????? ???????????????????????????????????????????????????? ?????????????????????????????????????? _ ????????????????????????????? ??????????????????? Python code ????????????????????????????????????????????? input_str ???????????????????????? (a, e, i, o ???? u) ??????????????????? v ?????????????????? replacevowel(input_str, v) ????????????????????? Hint: ?????????????????????????????????????????? a??? b ??????????????? = Note: ?????? Python ?????????????? syntax ???????? list ???? [“a”, “b”] ???????????? '''ab''' ???????????????????????????????????????????? ?????????????????????????????????????? 5 ?????????????????????????????????????? _ ???????????????????????????????????????????????????????????????????????? _ ?????????????????????????????????????????????? ???????????????????? a ??? e ??????????????? * ????????? i, o ??? u ??????????????? %??????????????????????????? $ ????????????????????? (Capital letter) ??????????????? + ???????????????????????? reflect_string(str1, str2) ?????????????????????????????????????????? str1 ??? str2 ????????????????????????????????????????????????????????????? (?????????????????????????????) ???? superman ??? namrepus ????????????????? ????????????????????????????????????? ???? “str1” and “str2” are reflected words ??????????????????????? They are not reflected words. ???????????????????????? AddOnlyMatch(numlist1, numlist2) ?????????????????? list ????????? list ???????????????????? ?????????????????????????????????????????????? list ?????????????????? ???????????????????????????????? ????????????????????????????????? list ???? ????????????????? ???? ??????????????? ???????? 0 ???? list ??????????????? list ???? (????????????????? outlist) ???????????????????????????????????????????numlist1 = [1, 3, 5, 6, 7]numlist2 = [2, 1, 2, 1, 3]outlist ?????????? [0, 4, 0, 0, 10] ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- python pass list as args
- python pass parameter to function
- is python pass by reference
- python pass list as parameter
- python pass by object reference
- python pass arguments to function
- python pass arguments to main
- python pass args by refer
- python pass arguments to script
- python pass parameter
- python pass tuple to function
- python pass by value