Programacion en Phyton

June 16, 2019 | Author: Benito Torres | Category: N/A
Share Embed Donate


Short Description

En este manual descubriras lo facil que resulta programar con Phyton, y lo mas interesante es que aprenderas a hacerlo d...

Description

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

-. c::J

hack"

crack

baslcos

Io

),todo

1. Introdu Introduccio ccio Python?

lnst lnstal alac acio ion, n, Holamundo

so el inte interp rpre rete te

decir: esto esto (2.6 (2.6 in nece necesi si

re

ific ific

bsol bsolut ut

te

.1 Instalaci6n

"interprete"

En Windo Windows: ws: Iar http://www.python.org/downloa http://www.python .org/download/releases/2.6 d/releases/2.6.6 .6 mas concretam concretamente ente http://www.python.org/fip/python http://www.python .org/fip/python/2.6.6/python /2.6.6/python

interactiva.

traves

gEdit

traves http://www.python.org/fip/python http://www.python .org/fip/python/2.6.6/Python /2.6.6/Python -2.6.6.tgz

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

c::J

crack

hack ww_ho

proqra proqrarna rnacio cio

ck)(c~ock-es

Python Python") ")

en inte interp rp et

so

inte interp rpre rete te

Un ve abie abiert rt el lnte lnterp rpre rete te apar aparec ecer er algo algo aSI: aSI:

ejec ejecut utam amos os esto esto most mostra rara ra el mens mensaj aje: e:

2.4 Comentario Comentario

Espos Esposib ible le intr introd oduc ucir ir come coment ntar ario io en arch archiv ivos os de

simp simple leme ment nt

se saltara llneas, cada cada line linea) a) po ejem ejempl plo: o:

ejecutar arch archiv ivos os qu cont conten enga ga

el codl codlqo qo

an alme alme te), te), solo solo del "»>". rc iv

scri scri irlo irlo

spue spue

fo "Archivo" vo" traves de "Archi

(0

util utiliz izar arem emos os "Nue "Nueva va vent ventan ana" a" (0 "New "New wind window ow qu obte obte re un fina finalm lmen ente te ejec ejecut utar arlo lo co "FS".

3. Variabl Variables es

de da dato to

ejemplo:

-*

ue cont cont en pasa

amplio.

trad trada/ a/ alid alid

nombre='Joe'

estandar

-*

Sequlra mostrando:

cade cadena na de cara cara tere tere

mism mism on la ejemplo: lo: nurneros, por ejemp i=10

ar bles bles ue

part part no mace macena na

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

crack

ck)(c~ock-es

se us en pyth python on

om seejec seejecut ut ra

ejem ejempl pl

no ha dive divers rsi6 i6n, n, lver lverda dad? d?

i=10

gu

a: sepa separa rado do po coma comas, s, po ejem ejempl pl

10

nombre=IJoe print Hola

comp compac acto to

lo coma comand ndos os

nombre

ma legi legibl ble. e. Mostraran

ejemplo (Yel curs cursor or qued quedar arfa fa aqul aqul i=200

aqu

fu espu espu as ig ient ient st vece vece no es ue uere uere os en esos esos mo ento ento caba cabare remo mo

i='xyz'

am iari iari

otra otras, s,

alor alor po

jemp jemp

stri string ng "x z" ar er ti usua usuari ri intr intr duci duci do coma comand ndos os inpu inpu raw_ raw_in inpu pu

si acem acemos os

var=i

string ejemplo:

vari variab able le i.

una pued pued crea crea un vari variab able le lIam lIamad ad

at

variab variable le nombr nombre. e.

:P). rime rimero ro

as

alor alor dire direct ctam am nt

(asfqu (asfqu

xi te

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

crack

ck)(c~ock-es

sigui siguient ent capitu capitulo lo

xi te aria ariabl bl "esp "espec ecia ial" l" Ia ad Ademas None None ("ni ("ning ngun una" a" co su prop propio io tipo tipo (Non (NoneT eTyp ype) e)

Ejemplo: comando

llamas?') p ri ri n ' Ho Ho l ' ,n ,n om om br br e

t y p ( v ar ar i ab ab l e

to

.1 Va iabl iabl

nu

ri as

despues con sigu siguie ient nte. e. En

bina binari rios os en real realid idad ad gene genera ra stri string ngs) s)

de entero enteros: s: qraf qraflc lc se perm permit iten en usaralg usaralgun unos os mas: mas: decimal numl=lO

num2=OxlO

ia yt on xist xisten en ario ario tipo tipo se mostra mostraran ran los siguie siguiente nte Nume Numero ro

Stri String ng (cad (caden enasde asde cara caract cter eres es Caractere Caractere individu individuales ales

sa

vari variab able les, s, qu num3=hex(numl)

sa float()

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

nt nt nt nt

ck)(c~ock-es

ml m2 m3 m4

Estomostr Esto mostrara ara

crack

4.

trin trings gs

pasa pasa un vari variab able le cual cualqu quie iera ra siguiente:

stri string ng se util utiliz iz

str(variable)

conc concat aten enar ar vari varias as cade cadena na de text text

se hace hace

cadenal='abcdef'

ente entero ro desp despue ue de se crea creada da po es la vari variab able le

se conv conver erti tida da

ci

cadena2='ghijklm'

cadena3=cadenal

uevo uevo). ).

cadena2

harlan

abcdefghijklm

ta nota nota espe especi cial alme ment nt en la divi divisi sion ones es »>

10/3

as c ad ad en en al al = ' qw qw er er ty ty ui ui o cadena2='er'

»>

3.3333333333333335 »> »>

1+1.

Mostrara

True

»>

cade cadena na no este este en la prim primer er most mostra rarf rf Fals Fals

»> »>

1/2.

len{cadena)

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

crack

ck)(c~ock-es

ti iz vece vece

ci

ca

vece vece

,p

rd cara caract ct r}

je pl

du

jemp jemplo lo

caracter=cadena[O] numero=ord(caracter) Mostrara

n um u m er er o

, nu n u me me r

blablabla chrt chrt um ro), ro),

je

lo

du numero=int(cadena) caracter=chr(numero) nt Mostrara

4.

caracter',caracter 4.

Boolea Booleano no

4.

Lista Lista

Carac Ca ractere tere

cadena='abcde£g' caracter=cadena[O] caracter=cadena[1]

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

c::J

crack

hack ww_ho

ck)(c~ock-es

nomb nombre re de lavaria lavariabl bl list lista} a}

prin prin

d_ej d_ej2[ 2['n 'no_ o_ex exis iste te'] ']

ic

funciones

hast hast num2 num2 (exc (exclu luye yend nd al ulti ultimo mo). ). Por ejemplo: ejemplo: condici6n vari varias as vece vece un part part de c6di c6digo go Mostrara:

estructura 4.6 Diccion Diccionario ario

Lo dicc diccio iona nari rios os so estr estruc uctu tura ra

qu

cualqu cualquier iera, a, par visual visualiza izarlo rlo mejor: mejor:

rela relaci cion onan an

condicional c6digo c6digo condicional c6digo c6digo c6digo

hace hace el c6di c6digo go ma legi legibl ble) e)

10

5.1 Con Condic diciona ionales les

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

crack

ck)(c~ock-es

ejec ejecut ut su c6di c6digo go

equi equivo voca cado do elif(numero!='2'):

siguient siguientes es operacio operaciones: nes: posi posibi bili lida da

3:

else:

prue prueba ba co

sigi sigien ente te si la cond condic ici6 i6

se cump cumple le

ta "Si, has acertado acertado apli aplica ca 5. co la mate matema matl tlca ca EIfun EIfunci cion onam amie ient nt

conv conven enci cion onal ales es

lo bool boolea eano no ta

Bucl Bucles es do ti os

esasi:

ejemplo: el

cond condic icio ion) n) i=10

el

bien bien

cond condic icio ion) n) i=i-1

bucl bucles es bucl bucl

hile hile

bucl bucles es fo

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

c:::::J

c::J

crack

hack ww_ho

ck)(c~ock-es

espegue!

[10,9,8,7,6,5,4,3,2,1,0]:

Mostrara: 10

Qu

rnos rnostr trar ar

cont contin inua uame ment nte: e:

la list list

la ca

(0 Verdad)

stri (0 stri

),

or

je

lo

Po ejempl ejemplo: o:

10:

lista (0

),

10

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

ck)(c~ock-es

.3 Funciones

defi defini nien endo do func funcio ione ne esto esto se hace hace asf: asf:

prop propia ia func funcio ione ne

( p ar ar a rn rn e tr tr o l, l, p ar ar a rn rn e tr tr o 2 c6digo

ar

crack

prop propia ias, s,

nurnerol=2 nurnero2=7 nurnero3=surna(nurnerol,nurnero2)

•.• ):

etre etre so vari variab ab es qu

ed

ejemplo: de f un un ci ci 6n 6n _d _d e_ e_ ej ej er er np np l (pararnetrol,parametro2=24): c6digo c6digo

ut liza liza

lgun lgun

ue

rm te

tras tras ue ermi ermite te mas compleja complejas. s.

hace hace inte interf rfac aces es

usar usar func funcio ione ne

ar sa un li rerf rerf se hace hace de esta esta form forma: a:

mate mate

condicional: c6digo_del_condicional c6digo_del_condicional c6digo_del_condicional c6digo_del_condicional

fu ci6n ci6n

ay

ti Ia acer acerlo lo de st form forma: a:

libreria.funci6n()

siguie siguiente nte c6digo c6digo

tica tica

ue impo import rt rl ", esto esto

la de lo cond condic icio iona nale les: s:

c6digo c6digo c6digo

rafi rafica cas, s,

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

crack

ck)(c~ock-es

librerfas basicas: import

6.

argc=len(sys.argv)

Libr Librer erra ra os

print for

in sys.argv: print

import

os.system('comando') Po ejemp ejemplo: lo:

que saldra

hablara

import

os.g os.get etcw cwdO dO,p ,por or

Ademas

ejem ejempl plo: o:

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

.'-= -. c::J

hack ww_ho

crack

ck)(c~ock-es

inp.close() outp.close()

lect lectur ur ye bina binari rio. o. archiv iv +, el arch escribir) Ejemplo: archivo=open('archivol','at+')

ermi ermiso so

ra to

si

exis existe te

ol crea.

ta

estandar, lgun lgun

reca recauc ucio ione ne para para vita vita

ti izan izan lasfu lasfunc ncio ione ne tr

xcep xcepti ti

archiv archivo.r o.rea ead(n d(nume umero_ ro_de de_ca _carat ratere eres_a s_a_le _leer} er} si no

arch archiv ivo. o.re read adli line neO, O,qu qu le un line line de arch archiv ivo. o. archivo.readlineO acab acab el arch archiv ivo. o.

te

try: f=open('archivo','r') except:

ue el c6di c6digo go ra se

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

-. c::J

hack ww.ha

or ulti ulti

st

ra se(t se(tip ip

ckxcrack.es

un

erro error, r,"D "Des escr cr pcio pcio

ta hemo creado. creado.

negativos: de

s ur ur na na (a (a ,b ,b )

www.google.es

p er e r rn r n it i t e n ur u r ne n e ro r o s n eg e g at a t iv i v os os ' else:

de pera peraci ci6n 6n rela relati tiva va ente ente

oc

omun omun pass pass

www.google.es.

ue serv servid idor or qu no envf envf la paql paqlna na web. web.

except. try: except: pass

www.google.es.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

hack ww.ha

c:::::l

-. c::J

ckxcrack.es

hace hace con conne connect. ct. escucha

socket.socket() «'

ey

func funci6 i6n, n, nece necesi sita tamo mo un vari variab able le para para lIev lIevar ar la cuentas prod produz uzca ca el avis aviso} o}

veces

escucha.listen(lO) rnostrara la vece veces, s, para para acce accede de

esto esto se hace hace co acce accept pt devu devuel elve ve

parametres,

rece rece as!.

co self self

nt nces nces la fu ci6n ci6n

ed rf

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

=,-: -. c::J

hack ww.ha

Eso tod na

crack

ckxcrack.es

nece necesa sari ri para para clas clases es basl baslca cas, s, pero pero ua ta func funcio ione ne ue perm permit it ce

p_

rnet rnet do qu xi ti ra lase lase inic inicia ial, l, se Ie llam llam sobr sobrec ecar arga ga de rnet rnetod odo, o, la clas claseshac eshacer er ma cosa cosas: s:

»> »>

nuevo_contador(10) c.cuenta()

11 »>

11

»>

True »>

nuev nuev clas clase,de e,desp spue ue de nomb nombre re de esta esta yant yantes es

c.cuenta()

12 »>

False

11

st

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

hack ww_ho

ue

en

mismo, asl

er

ie

....

crack

ckxcrock-es

am

»>

o..

»>

rasqare

uper uperfi fici ci

asl bien bien el capi capitu tulo lo ante anteri rior or toca toca volv volver er 10

na lase lase nuev nueva, a, qu se as en (her (her e) la cl se qu se pued pued enco encont ntra ra en thre thread adin ing. g.Th Thre read ad

12 13

()

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

Trusted by over 1 million members

Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.

hack ww_ho

=,.: . . . . crack ckxcrock-es

http://docs.python.org/release/2.6.6/Iibrary/mat h.ht h.html ml

Libr Librer erfa fa maternatlca

http://docs.python.org/release http://docs.pytho n.org/release/2.6.6/Iibrary/rand /2.6.6/Iibrary/rand aleatorios http://docs.python.org/release http://docs.pytho n.org/release/2.6.6/Iibrary/os.h /2.6.6/Iibrary/os.h

http://docs.python.org/release/2.6.6/Iibrary/sys. golosinas http://docs.python.org/release http://docs.pytho n.org/release/2.6.6/Iibrary/time /2.6.6/Iibrary/time !)

http://docs.python.org/release http://docs.pytho n.org/release/2.6.6/Iibrary/sock /2.6.6/Iibrary/sock

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF