forked from mouredev/Hello-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_strings.py
65 lines (46 loc) · 1.47 KB
/
03_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
# Clase 2 (10/08/22) en directo desde Twitch: https://www.twitch.tv/videos/1558018826
### Strings ###
my_string = "Mi String"
my_other_string = 'Mi otro String'
print(len(my_string))
print(len(my_other_string))
print(my_string + " " + my_other_string)
my_new_line_string = "Este es un String\ncon salto de línea"
print(my_new_line_string)
my_tab_string = "\tEste es un String con tabulación"
print(my_tab_string)
my_scape_string = "\\tEste es un String \\n escapado"
print(my_scape_string)
# Formateo
name, surname, age = "Brais", "Moure", 35
print("Mi nombre es {} {} y mi edad es {}".format(name, surname, age))
print("Mi nombre es %s %s y mi edad es %d" %(name, surname, age))
print("Mi nombre es " + name + " " + surname + " y mi edad es " + str(age))
print(f"Mi nombre es {name} {surname} y mi edad es {age}")
# Desempaqueado de caracteres
language = "python"
a, b, c, d, e, f = language
print(a)
print(e)
# División
language_slice = language[1:3]
print(language_slice)
language_slice = language[1:]
print(language_slice)
language_slice = language[-2]
print(language_slice)
language_slice = language[0:6:2]
print(language_slice)
# Reverse
reversed_language = language[::-1]
print(reversed_language)
# Funciones del lenguaje
print(language.capitalize())
print(language.upper())
print(language.count("t"))
print(language.isnumeric())
print("1".isnumeric())
print(language.lower())
print(language.lower().isupper())
print(language.startswith("Py"))
print("Py" == "py") # No es lo mismo