This file contains hidden or 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
| from sqlalchemy.orm import sessionmaker | |
| from conexao import engine | |
| from modelos import Pedido | |
| Session = sessionmaker(bind=engine) | |
| session = Session() | |
| pedido = session.query(Pedido).filter(Pedido.id == 1).first() | |
| if pedido: |
This file contains hidden or 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
| from sqlalchemy.orm import sessionmaker | |
| from conexao import engine | |
| from modelos import Funcionario | |
| Session = sessionmaker(bind=engine) | |
| session = Session() | |
| funcionario = session.query(Funcionario).filter(Funcionario.nome == "Ana Silva").first() | |
| if funcionario: |
This file contains hidden or 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
| from sqlalchemy.orm import sessionmaker | |
| from conexao import engine | |
| from modelos import Funcionario | |
| Session = sessionmaker(bind=engine) | |
| session = Session() | |
| funcionarios = session.query(Funcionario).all() | |
| for funcionario in funcionarios: | |
| print(f"ID: {funcionario.id}, Nome: {funcionario.nome}, Cargo: {funcionario.cargo}") |
This file contains hidden or 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
| from sqlalchemy.orm import sessionmaker | |
| from conexao import engine | |
| from modelos import Funcionario, Pedido | |
| Session = sessionmaker(bind=engine) | |
| session = Session() | |
| funcionaria_ana = Funcionario(nome="Ana Silva", cargo="Atendente") | |
| funcionario_carlos = Funcionario(nome="Carlos Souza", cargo="Gerente") | |
| pedido_cliente = Pedido(data="2025-01-24", valor_total=89.90) |
This file contains hidden or 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
| import os | |
| from dotenv import load_dotenv | |
| from sqlalchemy import create_engine | |
| from modelos import Base | |
| load_dotenv() | |
| database_url = os.getenv("DATABASE_URL") | |
| if not database_url: |
This file contains hidden or 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
| from sqlalchemy import Column, Integer, String, Float | |
| from sqlalchemy.ext.declarative import declarative_base | |
| Base = declarative_base() | |
| class Funcionario(Base): | |
| __tablename__ = 'funcionarios' | |
| id = Column(Integer, primary_key=True) | |
| nome = Column(String, nullable=False) | |
| cargo = Column(String, nullable=False) |
This file contains hidden or 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
| from enum import Enum | |
| # Inteiros sequenciais | |
| class Prioridade(Enum): | |
| BAIXA = 1 | |
| MEDIA = 2 | |
| ALTA = 3 | |
| URGENTE = 4 | |
| # Inteiros não sequenciais |
This file contains hidden or 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
| numero = -10 | |
| classificacao = "positivo" if numero > 0 else "negativo" if numero < 0 else "zero" | |
| print(f"O número é {classificacao}.") # Saída: O número é negativo. |
This file contains hidden or 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
| idades = [25, 17, 18, 40, 16] | |
| faixa_etaria = ["Adulto" if idade >= 18 else "Menor Idade" for idade in idades] | |
| print(faixa_etaria) # Saída: ['Adulto', 'Menor Idade', 'Adulto', 'Adulto', 'Menor Idade'] |
This file contains hidden or 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
| preco_pizza_frango = 25.00 | |
| preco_pizza_lombo = 30.00 | |
| # Condição usando o operador ternário | |
| escolha = "frango" if preco_pizza_frango <= preco_pizza_lombo else "lombo" | |
| print(f"Vou escolher a pizza de {escolha}!") # Saída: Vou escolher a pizza de frango! |
NewerOlder