-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringsB.py
50 lines (42 loc) · 986 Bytes
/
stringsB.py
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
#FIND (devolve a posicao) / -1 quando nao existe
word = "bananana"
i = word.find("na")
print(i)
#slicing Strins
s = "Monty Phyton"
print(s[0:4])
print(s[6:20])
print(s[:4])
print(s[6:])
print(s[:])
#String Concatenation
a = "\nOla "
b = a + s
print(b)
#Using IN as logical operator
fruit = "banana"
print("n" in fruit)
print("N" in fruit)
print("nan" in fruit)
#String lower()
#lstrip() remove espaço esquerda
#rstrip() remove espaço direita
#strip() remove espacos inciais a esquerda e direita
greet = " Ola Andre "
print(greet.strip().lower())
#String Methods
print("\n",dir(greet),"\n")
#Search and Replace
print(greet.replace("Andre", "Tomas"))
print(greet.replace(greet[0:4], "Hello"))
#Prefixes
word = "CZZZE"
print(word.startswith("C"))
#Parsing and Extracting
data = "From sousa@andremaciel.pt Sat Jan 5 09:14:16 2008"
atpos = data.find("@")
print(atpos)
sppos = data.find(" ",atpos) #procura o espaço depois do @
print(sppos)
host = data[atpos+1 : sppos]
print(host)