O GoConqr está de visual novo! Conte para nós o que você achou.

Notas

python basic

inga pinga python ACT Year 12 Certificate Inglês 1 página

Conteúdo das notas (1)

Página 1

Basics:

-Avoid _A or __AA as variable name

Strings:

-type(<variable>) : to get the type of the variable

>>> a = 'whatever'

>>> type(a)

<type 'str'>

>>> a = 'whatever'

>>> a[0]

'w'

>>> a[-1]

'r'

- strings are immutable, so we can make changes.

b = a

b is pointing to same object in memory

-

length function

-

>>> a

'whatever you want to do'

>>> len(a)

23

>>>

\n and \t

>>> c = 'c:\widows\new\test\dir'

>>> print c

c:\widows

ew est\dir

>>>

option 1:

use on more \

eg:

>>> c = 'c:\widows\\new\\test\dir'

>>> print c

c:\widows\new\test\dir

>>>

option 2:

use raw string:

>>> c = r'c:\widows\new\test\dir'

>>> print c

c:\widows\new\test\dir

String Methods:

1) strip():

This method returns a copy of the string in which all chars have been stripped from the beginning and the end of the string.

>>> print a

whatever

>>> print a.strip()

whatever

>>>

2) split()

>>> a = '192.168.1.10'

>>> print a.split('.')

['192', '168', '1', '10']

>>>

- output is a list

3) Join method

join a list with a delimiter

- >>> b

['192', '168', '1', '10']

>>> ".".join(b)

'192.168.1.10'

>>>

>>> a

'192.168.1.10'

>>> '192.168' in a

True

Printing

>>> a

'192.168.1.10'

>>> b

'255.255.255.0'

>>> print "router IP is %s and subnet mask is %s" %(a,b)

router IP is 192.168.1.10 and subnet mask is 255.255.255.0

>>>

>>> print "router IP is %s and subnet mask " % a

router IP is 192.168.1.10 and subnet mask

>>>

>>> a

3.14

>>> print "%.2f" % a

3.14

>>> router_name

'rtr1.blr1'

>>> ip_addr

'192.168.1.1'

>>> print "router name is {0} and IP address of router {0} is {1}".format(router_name,ip_addr)

router name is rtr1.blr1 and IP address of router rtr1.blr1 is 192.168.1.1

>>>

Informações

Descrição
ACT Year 12 Certificate python Notas sobre python basic, criado por inga pinga em 07-04-2016.
Criado por
inga pinga
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?