forked from bradtraversy/python_sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.py
More file actions
63 lines (42 loc) · 1.19 KB
/
Copy pathstrings.py
File metadata and controls
63 lines (42 loc) · 1.19 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Strings in python are surrounded by either single or double quotation marks. Let's look at string formatting and some string methods
name = 'Crystal'
age = 21
#Concatenate (basically means to insert a variable into a string)
#print ('Hello, my name is ' + name + ' and I am ' + str(age))
# String Formatting
#Arguments by position/Positional arguments
#print('My name is {name} and I am {age}'.format(name=name, age=age))
#Using F-stirngs (these are only available in Python 3.6+)
#print(f'Hello, my name is {name} and I am {age}')
# String Methods
s = 'hello world'
#Capitalize
print(s.capitalize()) #Capitalizes the first letter of the string
# Make all uppercase
print(s.upper())
# Make all lowercase
print(s.lower())
# Swap case
print(s.swapcase())
# Get length (gets the length of the string)
print(len(s))
# Replace
print(s.replace('world', 'Claire'))
# Count
#print(s.count('h'))
sub = 'h'
print(s.count(sub))
#Starts with
print(s.startswith('hello'))
# Ends with
print(s.endswith('d'))
# Split into a list
print(s.split())
# Find Position
print(s.find('r'))
# Is all alphanumeric
print(s.isalnum())
# Is all alphabetic
print(s.isalpha())
# Is all numeric
print(s.isnumeric())