I thought that an object followed by a "." And a "()" was a method, but range () is called a function.
As a result of investigation, methods and functions were used properly, so a summary.
Only available in ** specific classes **.
Example: replace method It cannot be used for list (array), but it can be used for str (character string).
replace cannot be used in list
list = ['AAA', 'BBB', 'CCC']
list.replace("A","B")
#output
# AttributeError: 'list' object has no attribute 'replace'
can be used with str
list = ['AAA', 'BBB', 'CCC']
str(list).replace("A","B")
#output
# "['BBB', 'BBB', 'CCC']"
The ** built-in function ** that is built into python by default is applicable.
| function | Contents |
|---|---|
| type() | Returns the type |
| tuple() | Convert to tuple type |
| str() | Convert to a string |
| set() | Convert to set type |
| range() | Returns an integer included in the specified range |
| open() | Open file |
| list() | Convert to list type |
| len() | Returns the number of elements |
| int() | Returns an integer (rounded down to the nearest whole number) |
| format() | Change the format |
-A list of built-in functions is here
Example: str function
Can be used for tuple
A = 1,2,3,4,5
type(A) #Output: tuple
type(str(A))
#output
# str
Can be used for list
B = [1,2,3,4,5]
type(B) #Output: list
type(str(B))
#output
# str
Can be used for set
C = {1,2,1,5,2,3,4,5}
type(C) #Output: set
type(str(C))
#output
# str
Recommended Posts