Sunteți pe pagina 1din 4

Leccion 8 (Apuntes) - Funciones integradas http://localhost:8888/nbconvert/html/Fase 2 - Manejo de datos y optimiz...

Funciones integradas comunes


int(): Transforma una cadena a un entero (si no es posible da error)

In [1]: n = int("10")
n

Out[1]: 10

float(): Transforma una cadena a un flotante (si no es posible da error)

In [2]: f = float("10.5")
f

Out[2]: 10.5

str(): Transforma cualquier valor a una cadena

In [7]: c = "Un texto y un número " + str(10) + " " + str(3.14)

In [8]: c

Out[8]: 'Un texto y un número 10 3.14'

bin(): Conversión de entero a binario

In [9]: bin(10)

Out[9]: '0b1010'

hex(): Conversión de entero a hexadecimal

In [10]: hex(10)

Out[10]: '0xa'

int() con base: Reconversión a entero (base 10)

In [11]: int('0b1010',2)

Out[11]: 10

In [12]: int('0xa',16)

Out[12]: 10

1 de 4 12/01/2018 08:41 a. m.
Leccion 8 (Apuntes) - Funciones integradas http://localhost:8888/nbconvert/html/Fase 2 - Manejo de datos y optimiz...

abs(): Valor absoluto de un número (distancia)

In [13]: abs(-10)

Out[13]: 10

In [14]: abs(10)

Out[14]: 10

round(): Redondeo de un flotante a entero, menor de .5 a la baja, mayor o igual a .5 al


alza

In [15]: round(5.5)

Out[15]: 6

In [16]: round(5.4)

Out[16]: 5

eval(): Evalúa una cadena como una expresión, acepta variables si se han definido
anteriormente

In [17]: eval('2+5')

Out[17]: 7

In [19]: #n = 10
eval('n*10 - 5')

Out[19]: 95

len(): Longitud de una colección o cadena

In [20]: len("Una cadena")

Out[20]: 10

In [21]: len([])

Out[21]: 0

help(): Invocar el menú de ayuda del intérprete de Python

2 de 4 12/01/2018 08:41 a. m.
Leccion 8 (Apuntes) - Funciones integradas http://localhost:8888/nbconvert/html/Fase 2 - Manejo de datos y optimiz...

In [ ]: help()

3 de 4 12/01/2018 08:41 a. m.
Leccion 8 (Apuntes) - Funciones integradas http://localhost:8888/nbconvert/html/Fase 2 - Manejo de datos y optimiz...

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type


"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> topics

Here is a list of available topics. Enter any topic name to get more help.

ASSERTION DELETION LOOPING SHIFTING


ASSIGNMENT DICTIONARIES MAPPINGMETHODS SLICINGS
ATTRIBUTEMETHODS DICTIONARYLITERALS MAPPINGS SPECIALATTRIBUTES
ATTRIBUTES DYNAMICFEATURES METHODS SPECIALIDENTIFIERS
AUGMENTEDASSIGNMENT ELLIPSIS MODULES SPECIALMETHODS
BASICMETHODS EXCEPTIONS NAMESPACES STRINGMETHODS
BINARY EXECUTION NONE STRINGS
BITWISE EXPRESSIONS NUMBERMETHODS SUBSCRIPTS
BOOLEAN FLOAT NUMBERS TRACEBACKS
CALLABLEMETHODS FORMATTING OBJECTS TRUTHVALUE
CALLS FRAMEOBJECTS OPERATORS TUPLELITERALS
CLASSES FRAMES PACKAGES TUPLES
CODEOBJECTS FUNCTIONS POWER TYPEOBJECTS
COMPARISON IDENTIFIERS PRECEDENCE TYPES
COMPLEX IMPORTING PRIVATENAMES UNARY
CONDITIONAL INTEGER RETURNING UNICODE
CONTEXTMANAGERS LISTLITERALS SCOPING
CONVERSIONS LISTS SEQUENCEMETHODS
DEBUGGING LITERALS SEQUENCES

help> ATRIBUTES
No Python documentation found for 'ATRIBUTES'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

help> ATTRIBUTES
Attribute references
********************

An attribute reference is a primary followed by a period and a name:

attributeref ::= primary "." identifier

The primary must evaluate to an object of a type that supports


attribute references, which most objects do. This object is then
asked to produce the attribute whose name is the identifier. This
production can be customized by overriding the "__getattr__()" method.
If this attribute is not available, the exception "AttributeError" is
raised. Otherwise, the type and value of the object produced is
determined by the object. Multiple evaluations of the same attribute
reference may yield different objects.

Related help topics: getattr, hasattr, setattr, ATTRIBUTEMETHODS

4 de 4 12/01/2018 08:41 a. m.

S-ar putea să vă placă și