-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_strings.py
77 lines (62 loc) · 1.08 KB
/
4_strings.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#cadenas de texto o cadenas de caracteres
#PONER PRINT
msg = ("el veloz murciélago hindu comí feliz cardillo y kiwi")
print = msg
type(msg)
#print(msg._class_)
#Operaciones con strings
#https://docs.python.org/3/library/stdtypes.html#str
#msg.capitalize()
#msg.title()
#msg.upper()
#msg.lower()
#len(msg)
a = "Un texto"
b = "Otro texto"
a.upper()
b.lower ()
len(a)
len(b)
#Conversión de objetos
msg[0]
"e"
msg[1]
msg[-2]
#Slice
msg[0:6]
'el vel'
#ejemplo con NIF
nif = "00000001R"
numero = nif[0:8]
letra nif (-1)
print(numero, letra)
msg[0:40:2]
msg[::-1]
msg.startswith("el veloz")
#true
msg.endswith("kiwi")
#true
msg.find("feliz")
msg[32:]
msg.find("el")
msg.rfind("el")
"cardillo" in msg
#True
"CARDILLO" in msg
#False
#Conversión de objetos a str
num = 3
type(num)
nums = str(num)
nums
type(nums)
#Ejemplo
a = 5
b = 3.4
s = a * b
print("El área de la figura es" + str(s) + "metros cuadrados"))
#El área de la figura es 19.04 metros cuadrados
#Repeticion
"Hola" * 3
#Concatenación
"unir" + "partes"