-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_strings.py
More file actions
68 lines (46 loc) · 1.57 KB
/
Copy path03_strings.py
File metadata and controls
68 lines (46 loc) · 1.57 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
64
my_string = "Mi string"
my_other_string = 'Mi otro string'
print (len(my_string))
print (len(my_other_string))
print (len(my_string) + len(my_other_string))
print(my_string + " " + my_other_string)
my_new_line_string =" Este es un string \n con salto de linea"
print(my_new_line_string)
my_tab_string = "\tEste es un string con tabulacion"
print(my_tab_string)
my_scape_string ="\\tEste es un String \n escapado"
print(my_scape_string)
my_scape_string ="\\tEste es un String \\n escapado"
print(my_scape_string)
#formateo de strings
name, surname, age = "Juan", "Perez", 25
print("Mi nombre es {}{} y tengo {} años".format(name, surname, age))#si queremos formatear datos
print("Mi nombre es %s %s y tengo %s años" % (name, surname, age))
print(f"Mi nombre es {name} {surname} y tengo {age} años")#manera estandar
#desempaquetado de strings
language = "Python"
a, b, c, d, e, f = language
print(a)
print(b)
print(c)
print(d)
print(e)
print(f)
#division
language_slice = language[1:3]
print(language_slice)
language_slice = language[1:]
print(language_slice)
language_slice = language[-2]
print(language_slice)
#reverse
reversed_language = language[::-1]
print(reversed_language)
#Funciones
print(language.capitalize())#primera letra en mayuscula
print(language.upper())#todas las letras en mayuscula
print(language.lower())#todas las letras en minuscula
print(language.count("t"))#cuenta cuantas veces aparece la letra t
print("1".isnumeric())#devuelve si es numerico
print(language.lower().isupper())#devuelve si es mayuscula
print(language.startswith("Py"))#devuelve si empieza con Py