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

Notas

Python

Jahangir Shah Python Inglês 4 páginas

Conteúdo das notas (4)

Página 1

Variables

string = 'this is a string'

int = 34

list = [1,2,3]

dict = {1:1,2:2,3:3}

Página 2

Function

def squared(num):

return num*num

print( squared(5) )

python function

Página 3

Classes

class Square :

# here we can define anything shared by all instances of this class

name = 'a squared number'

def __init__(self,num): # self is a convention, __init__ is where we add the attributes

self.num = num #optional

self.squared = num*num

square5 = Square(5).squared #creating an instance but only passing the squared number to square5.

print( square5 ) #so we can print the value here.

square10 = Square(10)#we can also instantiate

print( square10.squared )# then call it's attribute

print( square10.name )# or it's shared attribute

Página 4

Zip function

itemid = [1,2,3,4,5]

items = ['horses','sheep','cows','chickens','pigs']

item_zip = zip(itemid,items)

list_items = dict(item_zip)

print( list_items ) #will output {1: 'horses', 2: 'sheep', 3: 'cows', 4: 'chickens', 5: 'pigs'}

print( list_items[1] ) # will output horses

Informações

Descrição
Python Notas sobre Python, criado por Jahangir Shah em 01-10-2017.
Criado por
Jahangir Shah
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?