Aprendendo Google Colab - Cavalcante Treinamentos


Executar código é muito simples

Use CTRL + ENTER - Executa o código

ou SHIFT + ENTER - Executa o código e pula para a próxima célula

ou ALT + ENTER - Executa o código e cria uma nova célula


In [3]:
print('Olá seja bem vindo!!')


Olá seja bem vindo!!

Entrada de Dados


In [5]:
nome = input('Qual é seu nome: ')
print(nome + ' seja bem vindo ao curso de Python')


Qual é seu nome: Claudio
Claudio seja bem vindo ao curso de Python

Executar comandos Linux


In [6]:
!cat /proc/cpuinfo
!cat /proc/meminfo


processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 63
model name	: Intel(R) Xeon(R) CPU @ 2.30GHz
stepping	: 0
microcode	: 0x1
cpu MHz		: 2300.000
cache size	: 46080 KB
physical id	: 0
siblings	: 2
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat md_clear arch_capabilities
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs
bogomips	: 4600.00
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits physical, 48 bits virtual
power management:

processor	: 1
vendor_id	: GenuineIntel
cpu family	: 6
model		: 63
model name	: Intel(R) Xeon(R) CPU @ 2.30GHz
stepping	: 0
microcode	: 0x1
cpu MHz		: 2300.000
cache size	: 46080 KB
physical id	: 0
siblings	: 2
core id		: 0
cpu cores	: 1
apicid		: 1
initial apicid	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat md_clear arch_capabilities
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs
bogomips	: 4600.00
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits physical, 48 bits virtual
power management:

MemTotal:       13335180 kB
MemFree:        10841380 kB
MemAvailable:   12514668 kB
Buffers:           68520 kB
Cached:          1762788 kB
SwapCached:            0 kB
Active:           685928 kB
Inactive:        1564724 kB
Active(anon):     397260 kB
Inactive(anon):      320 kB
Active(file):     288668 kB
Inactive(file):  1564404 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:               420 kB
Writeback:             0 kB
AnonPages:        419348 kB
Mapped:           216892 kB
Shmem:               848 kB
Slab:             153052 kB
SReclaimable:     122596 kB
SUnreclaim:        30456 kB
KernelStack:        3552 kB
PageTables:         5312 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6667588 kB
Committed_AS:    2773132 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       65524 kB
DirectMap2M:     5177344 kB
DirectMap1G:    10485760 kB

Instalar biblioteca


In [7]:
!pip install requests


Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (2.21.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests) (2019.11.28)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests) (3.0.4)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests) (1.24.3)

In [8]:
!pip install tensorflow==1.2


Collecting tensorflow==1.2
  Downloading https://files.pythonhosted.org/packages/5e/55/7995cc1e9e60fa37ea90e6777d832e75026fde5c6109215d892aaff2e9b7/tensorflow-1.2.0-cp36-cp36m-manylinux1_x86_64.whl (35.0MB)
     |████████████████████████████████| 35.0MB 117kB/s 
Requirement already satisfied: wheel>=0.26 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.2) (0.34.2)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.2) (1.12.0)
Collecting bleach==1.5.0
  Downloading https://files.pythonhosted.org/packages/33/70/86c5fec937ea4964184d4d6c4f0b9551564f821e1c3575907639036d9b90/bleach-1.5.0-py2.py3-none-any.whl
Collecting html5lib==0.9999999
  Downloading https://files.pythonhosted.org/packages/ae/ae/bcb60402c60932b32dfaf19bb53870b29eda2cd17551ba5639219fb5ebf9/html5lib-0.9999999.tar.gz (889kB)
     |████████████████████████████████| 890kB 39.0MB/s 
Collecting markdown==2.2.0
  Downloading https://files.pythonhosted.org/packages/ac/99/288a81a38526a42c98b5b9832c6e339ca8d5dd38b19a53abfac7c8037c7f/Markdown-2.2.0.tar.gz (236kB)
     |████████████████████████████████| 245kB 45.7MB/s 
Requirement already satisfied: numpy>=1.11.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.2) (1.17.5)
Requirement already satisfied: protobuf>=3.2.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.2) (3.10.0)
Collecting backports.weakref==1.0rc1
  Downloading https://files.pythonhosted.org/packages/6a/f7/ae34b6818b603e264f26fe7db2bd07850ce331ce2fde74b266d61f4a2d87/backports.weakref-1.0rc1-py3-none-any.whl
Requirement already satisfied: werkzeug>=0.11.10 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.2) (1.0.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from protobuf>=3.2.0->tensorflow==1.2) (45.1.0)
Building wheels for collected packages: html5lib, markdown
  Building wheel for html5lib (setup.py) ... done
  Created wheel for html5lib: filename=html5lib-0.9999999-cp36-none-any.whl size=107220 sha256=ffe52163236fdaa6e3f23d196924366aa0deea20b7769367a56c81f4a6d288ae
  Stored in directory: /root/.cache/pip/wheels/50/ae/f9/d2b189788efcf61d1ee0e36045476735c838898eef1cad6e29
  Building wheel for markdown (setup.py) ... done
  Created wheel for markdown: filename=Markdown-2.2.0-cp36-none-any.whl size=136268 sha256=7976750d3030ebd91a50063df229134bbce3c3bbb7281f28683ff7e75effe19c
  Stored in directory: /root/.cache/pip/wheels/b6/52/17/f0af18e3e0ec6fa60b361ffed15b4c3468f6f3bcdb87fbe079
Successfully built html5lib markdown
ERROR: tensorboard 1.15.0 has requirement markdown>=2.6.8, but you'll have markdown 2.2.0 which is incompatible.
ERROR: stable-baselines 2.2.1 has requirement tensorflow>=1.5.0, but you'll have tensorflow 1.2.0 which is incompatible.
ERROR: magenta 0.3.19 has requirement tensorflow>=1.12.0, but you'll have tensorflow 1.2.0 which is incompatible.
Installing collected packages: html5lib, bleach, markdown, backports.weakref, tensorflow
  Found existing installation: html5lib 1.0.1
    Uninstalling html5lib-1.0.1:
      Successfully uninstalled html5lib-1.0.1
  Found existing installation: bleach 3.1.0
    Uninstalling bleach-3.1.0:
      Successfully uninstalled bleach-3.1.0
  Found existing installation: Markdown 3.2
    Uninstalling Markdown-3.2:
      Successfully uninstalled Markdown-3.2
  Found existing installation: backports.weakref 1.0.post1
    Uninstalling backports.weakref-1.0.post1:
      Successfully uninstalled backports.weakref-1.0.post1
  Found existing installation: tensorflow 1.15.0
    Uninstalling tensorflow-1.15.0:
      Successfully uninstalled tensorflow-1.15.0
Successfully installed backports.weakref-1.0rc1 bleach-1.5.0 html5lib-0.9999999 markdown-2.2.0 tensorflow-1.2.0

Saída de dados ricas


In [9]:
import numpy as np
from matplotlib import pyplot as plt

ys = 200 + np.random.randn(100)
x = [x for x in range(len(ys))]

plt.plot(x, ys, '-')
plt.fill_between(x, ys, 195, where=(ys > 195), facecolor='g', alpha=0.6)

plt.title("Fills and Alpha Example")
plt.show()


Utilizando a ajuda integrada

  1. Use a tecla tab para executar o Intelisense
  2. No final de um comando/função ou método adicione uma ?. E execute a célula SHIFT + ENTER.

In [0]:
import numpy as np
np.random?

Parar execução de um código mal comportado

CTRL+M I


In [11]:
while(True):
  pass


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-11-c8f15cbc0dcb> in <module>()
      1 while(True):
----> 2   pass

KeyboardInterrupt: 

Integração Drive e GitHub


Permite abrir e salvar arquivos nessas aplicações

Trabalhando de forma colaborativa

  1. Compartilhando seu código
  2. Adicionando e resolvendo comentários

In [0]:
texto = 'Claudio'

Executando o código em uma GPU ou TPU

Clicar em Edit > Noteboolk Settings

Adicionando fórmulas matemáticas para enriquecer seu texto

$\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$

$x^2 + 2xy + y^2 $

$\sqrt{3x-1}+(1+x)^2$

Adicionando Imagens e Links

Fazer um link é bem simples como isso Aprenda Python

Adicionar imagem faz dessa maneira:

Trocar o tema

Se você gosta de um tema mais dark é fácil trocar.

Tools => Settings


In [0]: