Skip to content

Instantly share code, notes, and snippets.

@Felipe-Marques
Created June 10, 2021 19:52
Show Gist options
  • Save Felipe-Marques/db09571d539cb7b2b31dc93e8cc51c47 to your computer and use it in GitHub Desktop.
Save Felipe-Marques/db09571d539cb7b2b31dc93e8cc51c47 to your computer and use it in GitHub Desktop.
Variaveis e Listas.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Variaveis e Listas.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyMGE5iuzlyWioO+VRmOI1p5",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/Felipe-Marques/db09571d539cb7b2b31dc93e8cc51c47/variaveis-e-listas.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "V4twAsuTG-Pu"
},
"source": [
"# 4.3 - Aula de Variaveis no Python - Bootcamp IGTI."
]
},
{
"cell_type": "code",
"metadata": {
"id": "5OU6FJcJ2-Lc"
},
"source": [
"# Bloco de criação de variaveis\n",
"nome = \"IGTI\" #string\n",
"idade = 29 #int\n",
"temperatura = 26.4 #real\n",
"matriculado = False # bool"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "7RoLKmeC4A7G",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "9ec6b158-8e2a-4513-f679-76ec2eead0ce"
},
"source": [
"# Bloco de impressão\n",
"print(\"O conteúdo da variavel é: \", nome)\n",
"print(\"A idade é \",idade, \" anos\")\n",
"print(temperatura)\n",
"print(matriculado)\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"O conteúdo da variavel é: IGTI\n",
"A idade é 29 anos\n",
"26.4\n",
"False\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "QtsUcPttG4s2"
},
"source": [
"# 4.4 - Aula de listas no Python - Bootcamp IGTI.\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "oFDaluQlHXNt"
},
"source": [
"#Bloco de Criação das Listas\n",
"Lista_1 = [] #Vazia\n",
"Lista_2 = [0,1,2,3,4,5] #Inteiros\n",
"Lista_3 = ['um', 'dois', 'três', 'quatro'] #Strings\n",
"Lista_4 = ['5', '6', True, 10] #Tipos diversos\n",
"Lista_5 = ['sete', [7,8,9,10] ] #com lista interna\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ShPzIc-KIoZU",
"outputId": "9ef880b2-c937-4f82-cd0b-aae057969f6b"
},
"source": [
"#Bloco de impressão e manipulação\n",
"print(Lista_1) #Impressão da Lista_1\n",
"Lista_1.append(11) #Adição na ultima posição da Lista_1\n",
"print(Lista_1)\n",
"Lista_1.insert(0,10) #Adição do valor(10) na posição determinada(0) \n",
"print(Lista_1)\n",
"print(Lista_1[1]) #Impressão do valor na posição determinada(1)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"[]\n",
"[11]\n",
"[10, 11]\n",
"11\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "lNXE5l9-KiQj",
"outputId": "f0a56640-75db-405b-9f16-bf56bcf57768"
},
"source": [
"#Bloco de Concatenação\n",
"Lista_6 = Lista_2+Lista_3 #Concatenação de listas\n",
"list(Lista_6) #Exibe a lista"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[0, 1, 2, 3, 4, 5, 'um', 'dois', 'três', 'quatro']"
]
},
"metadata": {
"tags": []
},
"execution_count": 21
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TVmzlz1uLGg1",
"outputId": "cd3bf889-ffbe-4079-bff5-e0f911d1af44"
},
"source": [
"#Bloco de Uso\n",
"print(2 in Lista_2) #Verifica se o número existe na lista\n",
"Lista_2.index(2) #Verifica o index(posição) do número na lista"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"True\n"
],
"name": "stdout"
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"2"
]
},
"metadata": {
"tags": []
},
"execution_count": 22
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "JoQTli5jYCAN"
},
"source": [
"# 4.5 - Aula de Listas no Python - Bootcamp IGTI."
]
},
{
"cell_type": "code",
"metadata": {
"id": "YyUGNzvOXjuz"
},
"source": [
"#Bloco de Criação das Listas e variaveis \n",
"estados = [\"Acre\", \"Distrito Federal\", \"Maranhão\", \"Santa Catarina\", \"São Paulo\"]\n",
"cidades = []\n",
"notas = [10,8,7,4]\n",
"compras = [\"banana\", \"abacaxi\", \"tomate\"]\n",
"mercado = [\"xampu\", \"sabonete\", [\"uva\", \"morango\", \"bergamota\"]]\n",
"lista = [\"um\", 2, \"três\", 4, True, [12, 34], 12.2]\n",
"\n",
"var1 = 20\n",
"var2 = \"texto\"\n",
"var3 = True\n",
"var4 = 50.2\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "GjJJCdwUZiqN",
"outputId": "7283de38-e444-45e4-f560-025f78f14482"
},
"source": [
"#Verificação de tipo de variavel\n",
"type(var4)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"float"
]
},
"metadata": {
"tags": []
},
"execution_count": 4
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "1dz_5jGvZzv7",
"outputId": "25f933da-bdf7-4fc6-cf2b-9441582c7876"
},
"source": [
"cidades\n",
"#cidades.append(\"São Luiz\") #Inserindo valor, sempre que for executado será adicionado \"São Luiz\" na lista. \n",
"#cidades.insert(1, \"Brusque\") #Inserindo valor a partir do index(1), sempre que for executado será adicionado \"Brusque\" na lista.\n",
"cidades"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"['São Luiz', 'Brusque', 'São Luiz']"
]
},
"metadata": {
"tags": []
},
"execution_count": 21
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 69
},
"id": "qMuTYUbIbHj7",
"outputId": "b5dba76b-2142-43fc-b492-cf16b37c0147"
},
"source": [
"#Concatenando Listas e percorrendo\n",
"feira = compras + mercado\n",
"feira #visualizando lista\n",
"\n",
"#Percorrendo Array interna\n",
"print(\"morango\" in feira[5])\n",
"print(feira[5].index(\"morango\"))\n",
"feira[5][1]"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"True\n",
"1\n"
],
"name": "stdout"
},
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'morango'"
]
},
"metadata": {
"tags": []
},
"execution_count": 36
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment