-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrings.html
228 lines (183 loc) · 6.36 KB
/
strings.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Cadenas - Python 101</title>
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<link rel="stylesheet" href="reveal.js/css/theme/white.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Cadenas - Python 101</h1>
<p>
<small>Por <a href="https://michelletorres.mx/acerca">Michelle Torres</a> / <a href="http://twitter.com/nmicht">@nmicht</a></small>
</p>
</section>
<section data-markdown>
<textarea data-template>
# Cadenas
Las cadenas en python se utilizan para caracteres o una secuencia de los mismos.
Se pueden representar con comillas simples `''` o con comillas dobles `""`.
```python
'una cadena'
"otra cadena"
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
Existen también cadenas de múltiple linea
```python
print("""\
Esta es una cadena con espacios
y de multiples lineas
que python acepta
""")
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
Los operadores de escape como `\n` funcionan tanto con comillas simples como en comillas dobles.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Concatenación
El operador `+` se utiliza para concatenar cadenas
```python
'ho' + 'la'
>>> hola
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
Sin embargo, en el ejemplo anterior se puede omitir el símbolo de `+` ya que python concatena por automático cualquier cadena que este contigua a otra.
```python
'ho' 'la'
>>> hola
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Repetir cadenas
Si se desea repetir una cadena, se puede realizar una "multiplicación"
```python
3 * 'Yo'
>>> YoYoYo
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Manejo de cadenas como secuencias
Python utiliza el tipo de dato secuencia para manipular las cadenas y las listas.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Acceder a elementos de la cadena por su indice
Los caracteres de una cadena se indexan a partir del cero de izquierda a derecha.
```python
word = 'Michelle'
word[3]
>>> h
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
Se utiliza también indices negativos para iniciar el conteo desde el final de la cadena. Estos inician en -1.
```python
word = 'Michelle'
word[-2]
>>> l
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Modificación de cadenas
**NOTA** Las cadenas no se pueden modificar, por lo cual no se pueden cambiar los valores de una posición.
```python
word = 'Michelle'
word[0] = 'm'
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Subcadenas
Para obtener porciones de una cadena se indica el indice para comenzar y el indice al que se quiere llegar (sin incluir).
```python
word = 'Michelle'
word[1:4] # Desde uno hasta 3
>>> ich
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
Se pueden usar tambien indices negativos
```python
word = 'Michelle'
word[-2:] # Desde -2 y hasta el final de la cadena
>>> le
```
</textarea>
</section>
<section>
<a href="./lists.html">Siguiente: Listas</a>
</section>
<section>
<h1>GRACIAS</h1>
<h3>Contáctame</h3>
<ul>
<li>hola@michelletorres.mx</li>
<li>@nmicht</li>
<li>https://michelletorres.mx</li>
</ul>
<p>
<small>Por <a href="https://michelletorres.mx/acerca">Michelle Torres</a> / <a href="http://twitter.com/nmicht">@nmicht</a></small>
</p>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
controls: true,
slideNumber: false,
dependencies: [
{ src: 'reveal.js/plugin/markdown/marked.js' },
{ src: 'reveal.js/plugin/markdown/markdown.js' },
{ src: 'reveal.js/plugin/notes/notes.js', async: true },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>