Last active
February 13, 2020 01:10
-
-
Save lfalanga/54fe4693fa71262797cf545588963c64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1 | |
x = 1 | |
y = 2 | |
z = ['juan'] | |
print(x, y, z, sep=' ') # 1 2 ['juan'] | |
print(x, y, z, sep=' , ') # 1 , 2 , ['juan'] | |
# Example 2 | |
print(x, y, z, sep=' , ', end='!\n') #1 , 2 , ['juan']! | |
# Example 3 | |
seq = [1, 2, 3, 4] | |
a, b, c, d = seq | |
print(a, b, c, d) # 1 2 3 4 | |
# Example 4 | |
a, *b = seq | |
print(a,b, type(b)) # 1 [2, 3, 4] <class 'list'> | |
# Example 5 | |
a, *b = 'Manzana' | |
print(a, b, type(b)) # M ['a', 'n', 'z', 'a', 'n', 'a'] <class 'list'> | |
# Example 6 | |
nombre = 'Pedro' | |
edad = 40 | |
print(f'La edad de {nombre} es de {edad} años') # La edad de Pedro es de 40 años | |
# Example 7 | |
valor1 = "Primer participante" | |
valor2 = "Anna" | |
valor3 = "xxx" | |
print(f'{valor1:30}==>{valor3:10}{valor2}') # Primer participante ==>xxx Anna | |
# Example 8 | |
valor = 3.141659 | |
print(f'El valor redondeado a 3 dígitos luego de la coma queda: {valor:.3f}.') # El valor redondeado a 3 dígitos luego de la coma queda: 3.142. | |
# Example 9 | |
votos = 42572654 | |
voto_en_blanco = 43132495 | |
porcentaje = (votos / (votos + voto_en_blanco)) * 100 | |
print('Los votos a favor son: {0} con un porcentaje de: {1:.2f}'.format(votos, porcentaje)) # Los votos a favor son: 42572654 con un porcentaje de: 49.67 | |
# Example 10 | |
import pprint | |
Juan = {'identificacion': {'nombre': 'Juan', 'apellido':'Garcia'}, 'edad': 24, 'sueldo': 5000, 'profesión': 'Pintor'} | |
Susana = {'identificacion': {'nombre': 'Susana', 'apellido':'Gomez'}, 'edad':25, 'sueldo': 6000, 'profesión': 'Empleada'} | |
db= {} | |
db['Juan'] = Juan | |
db['Susana'] = Susana | |
print(db) | |
print('\n*********\n') | |
pprint.pprint(db) | |
""" | |
{'Juan': {'identificacion': {'nombre': 'Juan', 'apellido': 'Garcia'}, 'edad': 24, 'sueldo': 5000, 'profesión': 'Pintor'}, 'Susana': {'identificacion': {'nombre': 'Susana', 'apellido': 'Gomez'}, 'edad': 25, 'sueldo': 6000, 'profesión': 'Empleada'}} | |
********* | |
{'Juan': {'edad': 24, | |
'identificacion': {'apellido': 'Garcia', 'nombre': 'Juan'}, | |
'profesión': 'Pintor', | |
'sueldo': 5000}, | |
'Susana': {'edad': 25, | |
'identificacion': {'apellido': 'Gomez', 'nombre': 'Susana'}, | |
'profesión': 'Empleada', | |
'sueldo': 6000}} | |
""" | |
# Example 11 | |
nombre = 'Pedro' | |
edad = 40 | |
print(f'{"fila":30}==>{nombre:10}{edad}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment