일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 밴픽
- Generator
- 30. Substring with Concatenation of All Words
- 109. Convert Sorted List to Binary Search Tree
- 파이썬
- Class
- Convert Sorted List to Binary Search Tree
- Regular Expression
- Decorator
- data science
- 315. Count of Smaller Numbers After Self
- concurrency
- Substring with Concatenation of All Words
- 715. Range Module
- DWG
- shiba
- attribute
- 컴퓨터의 구조
- Python
- LeetCode
- Python Implementation
- iterator
- kaggle
- 시바견
- Python Code
- 43. Multiply Strings
- 프로그래머스
- t1
- 운영체제
- Protocol
- Today
- Total
Scribbling
Python String Methods 본문
Refer to the website below for the detailed instructions.
https://www.w3schools.com/python/python_ref_string.asp
1. len(str)
- returns the length of the string
2. min(str), max(str)
- returns the min or max alphabetical character
3. str1.count(str2, begin, end):
- returns how many str2 is in str1[begin:end]
* Note that end index is not included
4. str1.startswith(str2, begin, end):
- returns whether str1 starts with str2
5. str1.endswith(str2, begin, end):
- returns whether str1 ends with str2
6. str1.rfind(str2)
- returns the index of the starting index of str2 in str1
- search starts from the right
- if str2 not in str1 -> returns -1
7. str1.index(str2)
- returns the index of str2 in str1
- if str2 not in str1 -> raises ValueError
8. str1.rindex(str2)
- returns the index of the starting index of str2 in str1
- search starts from the right
- if str2 not in str1 -> raises ValueError
9. str1.isalnum():
- returns whether str1 and all characters are alpahnumeric
10. str1.isalph()
- returns whether str1 and all characters are alphabetic
11. str1.isdigit()
- returns whether str1 and characters are digits
https://www.w3schools.com/python/ref_string_isdigit.asp
12. str1.isnumeric():
- returns whether str1 and characters are digits
- basically very similar to isdigit(), with some minor differences. check out the below link for details.
https://www.w3schools.com/python/ref_string_isnumeric.asp
13. str1.isdecimal():
- returns whether str1 and all characters are in [0-9]
14. str1.islower():
- returns whether str1 and allcharacters are in lowercase.
15. str1.isupper()
- returns whether str1 and allcharacters are in uppercase.
16. str1.lower()
- returns a string where all str1's uppercase letters are converted to lowercase ones.
17. str1.upper():
- returns a string where all str1's lowercase letters are converted to uppercase ones.
18. str1.swapcase()
- returns a string where all str1's lowercase letters are converted to uppercase ones and vice versa.
19. str1.istitle()
- returns whether str1 and str1 is properly "titlecased"
20. str1.title()
- returns a new string which is 'titlecased' form of str1
21. str1.capitalize()
- returns a new string str1 of which first character converted to uppercase
22. str1.lstrip(set of characters)
txt = ",,,,,ssaaww.....banana"
x = txt.lstrip(",.asw")
print(x)
txt =' moce'
x = txt.lstrip()
print(x)
23. str1.rstirp()
- returns a new string after removing spaces to the right of str1
24. str1.strip()
- if no params, returns a new string after removing spaces to the left & right of str1
- if params, returns a new string after removing those characters of str1
25. str1.isspace()
-returns whether str1 only consists of spaces
26. str1.center(width)
- returns a centered string with the given width
27. str.split(seperator, maxsplit)
- split the str to a list
https://www.w3schools.com/python/ref_string_split.asp
x = 'a b c d e f g'
l = x.split(maxsplit=3)
print(l)
28. str.splitlines(keeplinebreaks=False)
- returns a list with splitted string by line breakers
29. str.replace(oldvalue, newvalue, count)
https://www.w3schools.com/python/ref_string_replace.asp
30. str.join(iterable)
https://www.w3schools.com/python/ref_string_join.asp
31. str.zfill(len)
- adds zeros to the start of the string until the given length
32. str.ljust(length, character)
- left justifies the string and add characters until the given length
33. str.rjust(length, character)
- right justifes the string and add characters until the given length
txt = "banana"
x = txt.rjust(20, 'x')
print(x, "is my favorite fruit.")
34. str.format(val1, val2, val3...)
https://www.w3schools.com/python/ref_string_format.asp
'Computer Science > Python' 카테고리의 다른 글
Python Magic Methods: Pythonic Data Model (0) | 2022.03.16 |
---|---|
Python Grammar: Things that I forget often (0) | 2022.03.14 |
Python Int Representation & Bit Operations (0) | 2022.01.13 |
<Python> 정규표현식 (0) | 2021.11.09 |
<Python> Decorator (0) | 2021.11.09 |