Copyright (c) Hyperion Entertainment and contributors.
Difference between revisions of "AmigaOS Manual: Python Methods"
m (→.center()) |
m (→.center()) |
||
Line 19: | Line 19: | ||
<nowiki>stringobject.center(length[, fillchar])</nowiki> |
<nowiki>stringobject.center(length[, fillchar])</nowiki> |
||
− | Returns a string that is aligned to the center using character '''fillchar'''. The returned string is '''length''' characters long. If the specified length is less than the '''stringobject''' string's length, the original |
+ | Returns a string that is aligned to the center using character '''fillchar'''. The returned string is '''length''' characters long. If the specified length is less than the '''stringobject''' string's length, the original '''stringobject''' will be returned. If you omit the fill character, space will be used as a filler. |
For example: |
For example: |
Revision as of 18:24, 13 February 2021
Contents
- 1 Built-in Methods for Strings
- 1.1 .capitalize()
- 1.2 .center()
- 1.3 .count()
- 1.4 .decode()
- 1.5 .encode()
- 1.6 .endswith()
- 1.7 .expandtabs()
- 1.8 .find()
- 1.9 .index()
- 1.10 .isalnum()
- 1.11 .isalpha()
- 1.12 .isdecimal()
- 1.13 .isdigit()
- 1.14 .islower()
- 1.15 .isnumeric()
- 1.16 .isspace()
- 1.17 .istitle()
- 1.18 .isupper()
- 1.19 .join()
- 1.20 .len()
- 1.21 .ljust()
- 1.22 .lower()
- 1.23 .lstrip()
- 1.24 .maketrans()
- 1.25 .max()
- 1.26 .min()
- 1.27 .replace()
- 1.28 .rfind()
- 1.29 .rindex()
- 1.30 .rjust()
- 1.31 .rstrip()
- 1.32 .split()
- 1.33 .splitlines()
- 1.34 .startswith()
- 1.35 .strip()
- 1.36 .swapcase()
- 1.37 .title()
- 1.38 .translate()
- 1.39 .upper()
- 1.40 .zfill()
- 2 Built-in Methods for Lists
- 3 Built-in Methods for Sets
- 4 Built-in Methods for Dictionaries
Built-in Methods for Strings
.capitalize()
stringobject.capitalize()
Returns a string where the first character is upper case. For example:
text = "python for everybody." txt = text.capitalize() print( txt )
Output:
Python for everybody.
.center()
stringobject.center(length[, fillchar])
Returns a string that is aligned to the center using character fillchar. The returned string is length characters long. If the specified length is less than the stringobject string's length, the original stringobject will be returned. If you omit the fill character, space will be used as a filler.
For example:
text = "The Core of the Sun" txt = text.center( 25, '-' ) print( txt )
Output:
---The Core of the Sun---
.count()
stringobject.count(substring[, start][, end])
Returns the number of times the supplied string substring appears in the stringobject string. By default .count() searches the substring from the beginning of the stringobject string to the end of the string.
You can change the search range with the start and end parameters. The start parameter specifies the string position where the search range should start (0 is the start of the string) and the end parameter the string position where the search should end.
For example:
text = "I love AmigaOS. AmigaOS is my favourite operating system." times = text.count( "AmigaOS" ) print( times )
Output:
2
.decode()
stringobject.decode(encoding, errors)
.encode()
stringobject.encode(encoding, errors)
.endswith()
stringobject.endswith(suffix, start, end)
.expandtabs()
stringobject.expandtabs(tabsize)
.find()
stringobject.find(string, start, end)
.index()
stringobject.index(string, start, end)
.isalnum()
stringobject.isalnum()
.isalpha()
stringobject.isalpha()
.isdecimal()
stringobject.isdecimal()
.isdigit()
stringobject.isdigit()
Returns true if the string stringobject contains only digits.
.islower()
stringobject.islower()
.isnumeric()
stringobject.isnumeric()
.isspace()
stringobject.isspace()
.istitle()
stringobject.istitle()
.isupper()
stringobject.isupper()
.join()
stringobject.join(sequence)
.len()
stringobject.len()
Returns the length of the string stringobject.
.ljust()
stringobject.ljust(width[, fillchar])
.lower()
stringobject.lower()
.lstrip()
stringobject.lstrip()
.maketrans()
stringobject.maketrans()
.max()
stringobject.max(string)
.min()
stringobject.min(string)
.replace()
stringobject.replace(old, new[, max])
.rfind()
stringobject.rfind(string, start, end)
.rindex()
stringobject.rindex(string, start, end)
.rjust()
stringobject.rjust(width[, fillchar])
.rstrip()
stringobject.rstrip()
.split()
stringobject.split(delimiter, splits)
.splitlines()
stringobject.splitlines([keeplinebreaks])
Splits the string stringobject into a list. The splitting is done at line breaks. The optional parameter keeplinebreaks specifies if the line breaks should be included (True), or not (False). Default value is False
.startswith()
stringobject.startswith(string, start, end)
.strip()
stringobject.strip(characters)
.swapcase()
stringobject.swapcase()
.title()
object.title()
.translate()
stringobject.translate(translationtable[, deletechars])
.upper()
stringobject.upper()
.zfill()
stringobject.zfill(width)