Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- data distribution
- Github
- multiple lines
- Default X points
- MySQL
- For loops
- Else
- matplotlib.pyplot
- Text Analytics
- error
- polynomial regression
- machine learning
- SQL
- continue
- train/test
- iterates
- line width
- AS
- variables
- Python
- PANDAS
- __init__
- pie charts
- self parameter
- Text mining
- break
- matplotlib
- start exercise
- line color
- PROJECT
Archives
- Today
- Total
Data Science Explorer
[Basic Grammar] Python Strings: Slicing Strings 본문
반응형
- Slicing
You can return a range of characters by using slice syntax and should specify the start index and end index.
Example
Get the characters from position 1 to position 3 (not included):
b = "Hello, World!"
print(b[1:3])
- Slice from the Start
b = "Christmas"
print(b[:5])
- Slice to the End
b = "Christmas"
print(b[:8])
- Negative Indexing
b = "Hello, World!"
print(b[-5:-2])
Exercises
Please solve the following code.
text = "Hello, World!"
reversed_text = text[::-1]
print(reversed_text)
!dlroW ,olleH
In this code, the first ':' indicates the beginning of the slice. The empty space before the second ':' means the slice starts from the beginning of the sequence. '-1' specifies that the slice goes up to the end of the sequence in reverse order.
'Python' 카테고리의 다른 글
Pandas (0) | 2023.10.25 |
---|---|
[Basic Grammar] Python Strings: Modify Strings (0) | 2023.10.22 |
[Basic Grammar] Python Strings (1) | 2023.10.22 |
[Basic Grammar] Python Arrays (0) | 2023.10.21 |
[Basic Grammar] Python Lambda (1) | 2023.10.21 |