โรงเรียนบัวเชดวิทยา | คิดเป็น ทำเป็น แก้ปัญหาเป็น เพื่อ ...



Tuples ?????? PythonApril 15, 2017??????? ????????????????????????? Tuple ?????? Python ????????????????????? Tuple ??????? ???????????????????????????? Tuple ?????????????????????????????????????? ????????? ???????????????????????????????????????????? ??? Tuple????????????????????? Python ???? Tuple ?????????? List ??????????????????????? Tuple ?????????????????????????????????????????????? (Immutable) ???????????????????? ??????????????????????????????????????? Tuple ???? ???????????????????????????????????????? ???????? List ??????????????????????? Tuples ?????????????????????????????? ???????????????????????????????????????????????????????????????????????? List ?????????????? Loop ??? Tuple ??????????????????????????? ???????????????????????? Tuple ??????????????????????????????????????????????????????????????? Tuple ?????? Python?????? Python ????????? Tuple ??????????????????????? ??????????????????????????????? Tuple ??????????????????????? () ????????????????????????????????????????? (,) ??????????????????????????? Tuple ?????????????a = (1, 2, 3, 4)b = 1, 2, 3, 4c = tuple(['C++', 'C#', 'Java', 'Pyhton'])d = tuple(range(1, 10, 2))e = ('a', )f = ()print(a)print(b)print(c)print(d)print(e)print(f)?????????? ????????????? Tuple ?????????a?????b???????????????????????????? Tuple ????????????b????????????????????????????????????????????????????????? ????????????c?????d????????????????? Tuple ???????????????????tuple()???????????? List ???????????????????????????? (Iterable) ????????????range()????????????e?????????????????? Tuple ?????????????????????????????????????? (,) ??????????????????????? ???????????????????????????????????? String ??? ???????????????????f?????????????? Tuple ????????? ?????????????????????????? Tuple ????????????(1, 2, 3, 4)(1, 2, 3, 4)('C++', 'C#', 'Java', 'Pyhton')(1, 3, 5, 7, 9)('a',)()???????????????????????????????? ??????????? Tuple ????????????? ?????????????????????????????????????????? Tuple??????????????????????? Tuple ????????? Index ???????????? List ??????????????????? Index ????????? ?????????????????????????????????????? 1 Tuple ??????????????????????????????????????????????????????????????????????????????? ??????? Tuple ???????????????????????????? ????????????????????????? Tuple ?????? Pythonnumbers = (1, 2, 3, 4, 5)print('numbers[0] =', numbers[0])print('numbers[3] =', numbers[3])print('numbers[-1] =', numbers[-1])mixed_type = (1.1, 1, 'Python', [10, 20, 30])print('mixed_type[0] =', mixed_type[0])print('mixed_type[3] =', mixed_type[3])print('mixed_type[3][0] =', mixed_type[3][0])?????????? ?????????????????????? Tuple ????????????????? ???????numbers????????? Tuple ?????????????????????????? Integer ?????????????????????????????????numbers[0]???????????????????????numbers[3]????????????? Index ?????????????????? ??????????????? -1 ?????????????????????????? Tuple?????????????????????????mixed_type?????????????????????????????????? ???? ?????? String ??? List ?????????????????????????? Index ???????? ?????? Sequence ?????????? ?????????????? Index ??????????????????[m][n]????????????????mixed_type[3][0]numbers[0] = 1numbers[3] = 4numbers[-1] = 5mixed_type[0] = 1.1mixed_type[3] = [10, 20, 30]mixed_type[3][0] = 10??????????????????????????????? ??????????????????????? Tuple???????????? Tuple ?????????? For loop????????? Tuple ????????????????? Sequence ???????????? List ???????????????????????????????????? ???? For loop ??????????????????? Tuple ??????????????????????????????? Tuple ???????????????? For loop ?????? Pythonnumbers = (10, 20, 30, 40, 50, 60, 70, 80)for n in numbers: print(n, end = ' ')print()names = ('James', 'Alex', 'Bobby', 'Johnny', 'Nathan')for i in range(0, len(names)): print(names[i], end = ' ')?????????? ?????????? For loop ???????????????? Tuple ?????????????????????????????????numbers????????????????????????????in??????????????????????????????????? Tuple ??????????????????n?????????????????????? For loop ?????????? Index ??????? 0 ????????????????????????????? Tuple ??????? Index ??????10 20 30 40 50 60 70 80 James Alex Bobby Johnny Nathan ???????????????????????????????? ???????????????? Tuple ???????????????? For loopTuple slicing????????????? Tuple ???????????????????????????????? ??????????????? List ?????????????????????? Slicing ??????????????????????????????????????????? Tuple ????????????????????? ??????? slice ??????????????????? Index ??? Tuple?[start:end]?????????????n = (1, 2, 3, 4, 'Python', 'PHP', 'Java', 'Thailand', 'Ukraine')numbers = n[0:4]languages = n[4:7]countries = n[7:9]print(numbers)print(languages)print(countries)numbers2 = n[:4]string = n[4:]tuple = n[:] # tuple = nprint(numbers2)print(string)print(tuple)?????????? ?????????????? Tuple ???????????????????????????? Slice ????????????n?????????????????????????????? String ??????????????????????????????????????????????????????????????????????????????numbers = n[0:4]languages = n[4:7]countries = n[7:9]?????????????? ??????????? Slice ???????????????????????? Index ??????????? Index ?????????????????????????? ???????????????????????n[0:4]?????????????????????????? Tuple ????????????? 0 ??? 3 (?????? 4) ???????????????????????????????n?????????????????????????numbers??????????????????????????????????????????????????????????????????????? ????????numbers2 = n[:4]string = n[4:]tuple = n[:] # tuple = n??????????????????????????????????????? Index ??????????????????????? ???????????????????????????????????????????????????????? Tuple ?????????????????????????????????????????????????????? Tuple(1, 2, 3, 4)('Python', 'PHP', 'Java')('Thailand', 'Ukraine')(1, 2, 3, 4)('Python', 'PHP', 'Java', 'Thailand', 'Ukraine')(1, 2, 3, 4, 'Python', 'PHP', 'Java', 'Thailand', 'Ukraine')???????????????????????????????? ????????????????? Tuple ??????? SlicePython Tuple methods??????????????? Tuple ????????????????????? ??????????????????????????????? List ?? ?????????count()??????????????????????????? Tuple ?????????index()?????????????????????????????????? Tuple ?????????????????????????? Tuple ?????? Pythonlanguages = ('Python', 'PHP', 'Java', 'C#', 'C++')print('Count for "Python" =', languages.count('Python'))print('Index of "Python" =', languages.index('Python'))print('Index of "C#" =', languages.index('C#'))?????????? ????????????????????? Tuple ????????????languages?????????????????????????????????? ???????????????count()???????????????'Python'???????????? Tuple ?????????index()???????????? Index ??????????????? TupleCount for "Python" = 1Index of "Python" = 0Index of "C#" = 3??????????????????????????????????????????? Tuple ?????? PythonPython Tuple functions?????? Python ??????????????????? ?????????????? Sequence ????????????? List ??? Tuple ?????????????????????????????????????????????? ??????????????? built-in function ??? TupleFunctionDescriptionall(iterable)??????????True??????????????????? Tuple ????????any(iterable)???????????True????????????????????????????? Tuple ????????enumerate(iterable)?????????????? enumerate ?????????????????????? Key ??? Value ??? Tuplelen(iterable)??????????????????????????????? Tuplemax(iterable)??????????????????????????????? Tuplemin(iterable)???????????????????????????????? Tuplesorted(iterable)?????????????? List ???????????????????????sum(iterable)?????????????????????????????? Tupletuple(iterable)??????????????? ???? List ???? String ??????? Tuple??????? ??????????????????????????????????????????????????????????? Tuple ????????????????? Tuple ?????? Python ?????????????????????? ?????????????????????? Slice ????????????????? Tuple ?????????????????? ????????????????????????????????? Tuple ?????????????????????????? ??? built-in functions ??? Tuple ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download