Www.buached.ac.th



String methodsApril 7, 2017?·?1,327 views???????????? ??????????????????????????? String ????????????????? ??????? ?????????????????????????????????????? String ?????? Python ???? String ?????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Find and search????????? String ?????????????????? ?????????????? String ????????????????????????????????????????????????????????????????????????????????????? String ???????????????????????????????????????? Pythons = 'mountain'print(s.startswith('moun'))print(s.endswith('in'))print(s.find('n'))print(s.rfind('n'))print(s.replace('moun', 'con'))print(s.count('a'))?????????? ??????????????????????????????????????????????????? String ?????????startswith()????????????????????????? String ?????????????????'moun'???????? ?????????endswith()???????????????? String ???????????'in'???????? ???????????????? String ???????????????????????????????????????????print(s.find('n'))print(s.rfind('n'))?????????????????????find()?????????????????? Index ??? Sub string?'n'???????????????? String ?????????rfind()???????????????????????????????????????????????? ????????? Index ???? 3 ??? 7 ????????print(s.replace('moun', 'con'))print(s.count('a'))?????????replace()??????????????????????????? Srting ?????????????????????'moun'??????'con'?????????????????????????????????????????? String ?????????????????????????? ?????????count()??????????????????????????????????? String ????????????????????????????'a'???????????????????? StringTrueTrue37contain1???????????????????????????????? ?????????????????????????????????????????????????? StringText and sentence?????? Python ??????? String ????????????????????????????? text ?????????? ??????????????????????????????????????????????????????????????????????????????????????????? ???? ???????????????????????????????????????????? ????????????????????????????????????????????? ??????? ????????????????????s = 'this is a game that i love to play.'print(s.capitalize())print(s.title())print(s.upper())print(''.lower())?????????? ??????????????????????? ????????????????????? ??????capitalize()???????????????????????????????? String ???????????????? ??????????????title()???????????????????????? ????????????? white space ??????????????????????????????????upper()???????????????????????? String ???????????????? ?????????lower()???????????????????????? String ????????????????This is a game that i love to play.This Is A Game That I Love To Play.THIS IS A GAME THAT I LOVE TO PLAY.???????????????????????????????? ????????????????????????????????????????????????????????????????????Formatting string?????? Python ??????????? String ??????????????????????????? String ?????????????????????? ???? ??????????????????????? String ?????????????????????????????????????? String ?????????????????????s = 'Python'print(s.center(10))print(s.ljust(10))print(s.rjust(10))print(s.center(10, '#'))print(s.ljust(10, '#'))print(s.rjust(10, '#'))number = '83'print(number.zfill(6))print('-1.32'.zfill(8))?? 3 ???????? ?????????????????????????????????????????????????????????????????????? ??????center()?????????????????????????????????????????????? String ??????????????????? ??????????ljust()????????????????????????????????????????????????? ?????????rjust()????????????????????????? ??????????????????????????? String ??????? ??????????????????????????????????????????????????????????????????? ???????? Default ???? Space ?????????zfill()????????????????????? 0 ????????????????? String ????????????????????? Python Python Python##Python##Python########Python000083-0001.32?????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????'Python'???????????????????????????????'#'????????????????? 0 ??????????????? String ??????????????s = ' Python 'print(s.strip())print(s.lstrip())print(s.rstrip())s2 = '----marcuscode----'print(s2.strip('-'))print(s2.lstrip('-'))print(s2.rstrip('-'))?????????????????????????????? ???????????????????????????????????????????? ?????????strip()????????????????????????????????????????????????????????? ??????rstrip()????????????????????? ?????????lstrip()?????????????????? ???????????????????????????????????????? ???????? Default ???? Space ????????????????????PythonPython Pythonmarcuscodemarcuscode--------marcuscode???????????????????????????????? ?????????????????????????????????????????????????????????? String ????????????????????????????????-????????????????????????? String?????? Python ???????????format()???????????????????????????? String ??????????? String interpolation ????????????????????????????????????????????????????????print()??????????????????????print('a = {0}'.format(3))print('{0} loves to learn {1}'.format('Mateo', 'Python'))?????????????????format()?????????????????????????????????????? String ?????????{n}????????n???????????????????????????????????????????????????????????????????????????? 0 ????????? ??????????????????????????????????????? ?????????????????????????????????????? ???????????{1}???????????????????????????????a = 3Mateo loves to learn Python????????????????????????????????Type checking??????????????????? String ?????????????????????????????????????????????????? String ???????????????????????????? ???? ???????????????????????????? String ??????? ?????????????? String ????????????????????? ??????? ?????????????????????# tesing trueprint('marcuscode2017'.isalnum())print('bobby'.isalpha())print('1234'.isdecimal())print('1234'.isdigit())print('1234'.isnumeric())print('mateo'.islower())print('MATEO'.isupper())# tesing falseprint('marcuscode 2017'.isalnum()) # has spaceprint('bobby1'.isalpha()) # has numberprint('7F'.isdecimal()) # F is not decimalprint('1234A'.isdigit()) # A is not digitprint('Python'.isnumeric()) # not numberprint('Mateo'.islower()) # M is upper caseprint('Mateo'.isupper()) # Not all are upper case?????????? ??????????????????? String ?????????????? ????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????? ???????????????????????????????????TrueTrueTrueTrueTrueTrueTrueFalseFalseFalseFalseFalseFalseFalseList and sequence methods??????????????? String ??????????????????????????? List ???????? String ?????????????????????????????join()??????????????????? String ??????????split()???????????splitlines()??????????????????????????????????????countries = ['England', 'Turkey', 'Poland', 'Russia', 'Germany']print(', '.join(countries))lang = 'Java PHP C++ Python C#'print(lang.split(' '))text = 'Python is a language\nused to create a web,\n'text += 'desktop application\nand more'text2 = text.splitlines()for t in text2: print(t)?????????? ?????????????????countries??????????????????????????????? ????????????join()????????? String ??????????????????????????????', '?????????????lang??????????????????????????????????? ????????????split()????????? String ???????????????????????????????????? ??????????????????????????????????????????????????????? ????????????splitlines()???????????? String ?????????????????????England, Turkey, Poland, Russia, Germany['Java', 'PHP', 'C++', 'Python', 'C#']Python is a languageused to create a web,desktop applicationand more??????????????????????????????????????? ???????????????????????????????????? String ????????????? ???? ???????????????????????????? Index ??? String ???????????????????????? String ??????????????????????????????? ???????????????????????????? String ?????????????????????????????????? String ??????? ????????????????????????????????????? ???????????????????????????????????????????????????????? Python ???? ................
................

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

Google Online Preview   Download