If you do need to iterate over a sequence of numbers, the built-in function range() comes in handy. It generates lists containing arithmetic progressions, e.g.:
>>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
The given end point is never part of the generated list; range(10) generates a list of 10 values, exactly the legal indices for items of a sequence of length 10. It is possible to let the range start at another number, or to specify a different increment (even negative):
>>> range(5, 10) [5, 6, 7, 8, 9] >>> range(0, 10, 3) [0, 3, 6, 9] >>> range(-10, -100, -30) [-10, -40, -70]
To iterate over the indices of a sequence, combine range() and len() as follows:
>>> a = ['Mary', 'had', 'a', 'little', 'lamb'] >>> for i in range(len(a)): ... print i, a[i] ... 0 Mary 1 had 2 a 3 little 4 lamb
My example:
x=['mastery25','tc1014']
for i in range (len(x)):
print ("#",x[i])
>>>#mastery25
>>>#tc1014
#mastery25
#tc1014
GILBERTO ROGEL GARCÍA
SOURCE: Here
Continue reading ]]>If you do need to iterate over a sequence of numbers, the built-in function range() comes in handy. It generates lists containing arithmetic progressions, e.g.:
>>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
The given end point is never part of the generated list; range(10) generates a list of 10 values, exactly the legal indices for items of a sequence of length 10. It is possible to let the range start at another number, or to specify a different increment (even negative):
>>> range(5, 10) [5, 6, 7, 8, 9] >>> range(0, 10, 3) [0, 3, 6, 9] >>> range(-10, -100, -30) [-10, -40, -70]
To iterate over the indices of a sequence, combine range() and len() as follows:
>>> a = ['Mary', 'had', 'a', 'little', 'lamb'] >>> for i in range(len(a)): ... print i, a[i] ... 0 Mary 1 had 2 a 3 little 4 lamb
My example:
x=[‘mastery25′,’tc1014’]
for i in range (len(x)):
print (“#”,x[i])
>>>#mastery25
>>>#tc1014
#mastery25
#tc1014
GILBERTO ROGEL GARCÍA
SOURCE: Here
]]>Muchachos es #MasteriesTime
#TC1017
Aqui les dejo el link de un vdeo en donde explico como funcionan los strings les recomiendo verlo
saludos!
Continue reading ]]>Muchachos es #MasteriesTime
#TC1017
Aqui les dejo el link de un vdeo en donde explico como funcionan los strings les recomiendo verlo
saludos!
]]>#Mastery25 #TC1017 https:/
Creation and use of strings in C++
Primero llamamos a la libreria usamos using namespace std; y llamamos a nuestra funcion principal int main.
Despues definimos nuestras variables string, int, y char. Un string es un contenedor diseñado para operar con strings de caracteres de un solo byte.
Despues usamos la funcion legnth para tener el numero de digitos en el numero.
Usamos un ciclo for para comparar el digito con todos los digitos en un numero.
Si el digito del numero es igual al numero de digito, el contador incrementa.
Imprimimos el numero de veces que el digito esta en nuestro numero con un simple cout.
Usamos return 0 para terminar el programa, compilamos y corremos para ver que no haya ningun error.
Aquí esta un ejemplo de un programa corriendo utilizando strings:
#mastery25
Continue reading ]]>Creation and use of strings in C++
Primero llamamos a la libreria
Despues definimos nuestras variables string, int, y char. Un string es un contenedor diseñado para operar con strings de caracteres de un solo byte.
Despues usamos la funcion legnth para tener el numero de digitos en el numero.
Usamos un ciclo for para comparar el digito con todos los digitos en un numero.
Si el digito del numero es igual al numero de digito, el contador incrementa.
Imprimimos el numero de veces que el digito esta en nuestro numero con un simple cout.
Usamos return 0 para terminar el programa, compilamos y corremos para ver que no haya ningun error.
Aquí esta un ejemplo de un programa corriendo utilizando strings:
#mastery25
]]>The C-style character string originated within the C language and continues to be supported within C++. This string is actually a one-dimensional array of characters which is terminated by a null character ''. Thus a null-terminated string contains the characters that comprise the string followed by a null.
#Mastery25
#TC1017
Example:
Continue reading ]]>
The C-style character string originated within the C language and continues to be supported within C++. This string is actually a one-dimensional array of characters which is terminated by a null character ‘