GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python_programming_/string_in_python (2).py at main · machphy/python_programming_

Expand file tree

/

string_in_python (2).py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
48 lines (31 loc) · 1.49 KB
/

string_in_python (2).py

Copy path

File metadata and controls

48 lines (31 loc) · 1.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Example of string methods
# Initial string
text = " Hello World Python "
# Convert to lowercase
print(text.lower()) # Output: " hello world python "
# Convert to uppercase
print(text.upper()) # Output: " HELLO WORLD PYTHON "
# Capitalize each word
print(text.title()) # Output: " Hello World Python "
# Strip leading and trailing spaces
print(text.strip()) # Output: "Hello World Python"
# Replace 'Python' with 'Programming'
print(text.replace("Python", "Programming")) # Output: " Hello World Programming "
# Split the string into a list of words
print(text.split()) # Output: ['Hello', 'World', 'Python']
# Join a list of words into a single string with spaces
words = ['Hello', 'World', 'Python']
print(" ".join(words)) # Output: "Hello World Python"
# Find the position of 'World'
print(text.find("World")) # Output: 11
# Check if the string starts with ' Hello'
print(text.startswith(" Hello")) # Output: True
# Check if the string ends with 'Python'
print(text.endswith("Python ")) # Output: True
# Check if the string contains only digits
print("12345".isdigit()) # Output: True
# Check if the string contains only alphabetic characters
print("Hello".isalpha()) # Output: True
### Key Points
# - **Strings are immutable:** Methods that modify a string return a new string rather than changing the original string.
# - **Method chaining:** You can chain methods together for more complex operations. For example, `text.strip().upper().replace("WORLD", "EVERYONE")`.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.