- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path008_strings.py
More file actions
Latest commit
54 lines (42 loc) · 1.32 KB
/
Copy path008_strings.py
File metadata and controls
54 lines (42 loc) · 1.32 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
# raw string
print(r"I'll be ignored \n")
print("Hello "+"You") # concatenation
# some more
stringExample="Hello You"
print("Length: ", len(stringExample))
print("1st character: ", stringExample[0])
print("Last character: ", stringExample[-1])
# 1st 3 characters
print("1st 3", stringExample[0:3])
# Other characters
print("Every Other", stringExample[0:-1:2])
# replace
stringExample=stringExample.replace("Hello", "Goodbye")
print(stringExample)
# add y into the string
stringExample=stringExample[:8] +"y"+stringExample[9:]
print(stringExample)
# check if "you" are in stringExample
print("you"notinstringExample)
# find "you" at index
print("You index", stringExample.find("you"))
# trim blank spaces
print(" Hello ".strip())
# separate words with spaces
print(" ".join(["Some", "words"]))
# delimiters
# split words and put it into list or commonly called an array,
# tho i think that python's list behave more like vector because it's dynamic
print("A string".split(" "))
# btw you can do this # python is mind blowing
int1=int2=5
print(f"{int1} + {int2} = {int1+int2}")
# convert to lower case
print("A string".lower())
# convert to upper case
print("A string".upper())
# checks if the string is a character or a number
print("AString123".isalnum())
print("AString".isalpha())
print("123".isdigit())
# all true!