Acceder Registrarme

Bases fundamentales de Python (Código de ejemplo simple)


Por: Kevin Arnold Arias Figueroa Publicado el: 2020-02-08 18:13:05
print('Hello world from Codideep')

print(type('Hello world from Codideep'))

print(type(7))

print('Hello world'+' '+'from Codideep')

print(7+5)

print(True | False)

print(7.5)

print(['Hola', 'Chao', 7, True, 7.7])

print(list(('Hola', 'Chao', 7, True, 7.7)))

print(list(range(1, 10)))

print(('Codideep', 7, True))

print(len(['Codideep', 7, True]))

print(['Codideep', 7, True][0])

print(['Codideep', 7, True][-1])

print('Codideep' in ['Codideep', 7, True])

myList = ['Codideep', 7, True]

myList.append('Empresa')

print(myList)

myList.extend(['Otro', 'Valor'])

print(myList)

myList.insert(1, 'Pos')

print(myList)

myList.remove('Pos')

print(myList)

myList.pop(1)

print(myList)

print(myList.clear())

print([])

otherList = ['a', 'c', 'b']

otherList.sort()

print(otherList)

otherList.sort(reverse=True)

print(otherList)

print(otherList.index('b'))

print(otherList.count('b'))

print({

    'name': 'Codideep',

    'type': 'E.I.R.L.',

    'status': True

})

print(None)

name = 'Kevin Arnold'

print(name)

x, y = 7, 5

print(str(x)+' '+str(y))

print(x, y)

print(f'{x}, {y}')

print('{}, {}'.format(x, y))

print(dir(name))

print(name.upper())

print(name.lower())

print(name.swapcase())

print(name.capitalize())

tempWorld = 'Esto es una prueba y esto es para prueba de esto que aplicaré'

print(tempWorld)

print(tempWorld.replace('esto', 'reemplazado'))

print(tempWorld.count('esto'))

print(tempWorld.startswith('Est'))

print(tempWorld.startswith('est'))

print(tempWorld.endswith('ré'))

print(tempWorld.endswith('re'))

print(tempWorld.split(' '))

print(tempWorld.find('o'))

print(tempWorld.index('o'))

print(tempWorld.find('k'))

# print(tempWorld.index('k')) Genera error

print(len(tempWorld))

print(tempWorld.isnumeric())

print(tempWorld.isalpha())

print(tempWorld[1])

print(tempWorld[-1])

print(7/2)

print(7//2)

print(9.5/2)

print(9.5//2)

print(7/2)

print(5**2)

print(5 % 2)

name = input('Nombre: ')

print(name)

x = input('x: ')

y = input('y: ')

print(float(x)+float(y))

if(10 > 7):

    print('Correcto')

elif(10 == 7):

    print('Intermedio')

else:

    print('Incorrecto')

if(10 > 7 and 10 < 7):

    print('Nunca se imprirmiará')

if(True or False):

    print('Siempre imprimirá')

if(not(False)):

    print('También siempre se accederá aquí')


# En los bucles funcionan perfectamente "break" y "continue"

for value in ['Codideep', 7, True]:

    print(value)

person = [

{

    'name': 'Kevin Arnold',

    'old': 29

}]

for value in person:

    print(value['name'])

for value in 'Codideep':

    print(value)

while False:

    print('Nunca se imprimirá')

def greet(name):

    return 'Saludos desde '+name

print(greet('Codideep'))

add = lambda paramOne, paramTwo: paramOne + paramTwo

print(add(7, 5))


# Manejo de módulos


import datetime

# from datetime import date "Usar 'comas' para importar más de una función o método del módulo"

print(datetime.date.today())