Last active
March 21, 2016 19:25
-
-
Save luxedo/2452cb0d8f9b042dc3ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
''' | |
Mutavel e imutavel | |
''' | |
from UserDict import UserDict | |
numero = 2 | |
dumero = numero | |
print 'antes' | |
print numero, dumero | |
dumero += 1 | |
print 'depois' | |
print numero, dumero | |
print 'alterei "dumero" e "numero" permaneceu intacto\n' | |
lista = [2] | |
pista = lista | |
print 'antes' | |
print lista, pista | |
pista.append(1) | |
print 'depois' | |
print lista, pista | |
print 'alterei "pista" e "lista" alterou!!!' | |
print 'pista é uma referência pro mesmo lugar!!! vamos tentar com dict\n' | |
dicte = {'boi': 2} | |
livro = dicte | |
print 'antes' | |
print dicte, livro | |
livro['vaca'] = 1 | |
print 'depois' | |
print dicte, livro | |
print 'alterei "dicte" e "livro" alterou!!!\n' | |
print 'vamos tentar uma classe' | |
class Mafagago(object): | |
def __init__(self, **kwargs): | |
self.bola = 2 | |
def metodogafo(self): | |
print 'metodogafo' | |
return 'ohyeah' | |
meu_tile = Mafagago() | |
print meu_tile.metodogafo() | |
meu_tile2 = meu_tile | |
print 'meu_tile e meu_tile2 estão no mesmo lugar?? ', | |
print id(meu_tile2) == id(meu_tile) | |
meu_tile2.bola += 10 | |
print 'Alterei o attr bola em meu_tile2, será que vai alterar em meu_tile?' | |
print meu_tile2.bola, 'meu_tile2' | |
print meu_tile.bola, 'meu_tile' | |
print 'oh man!!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment