Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

314
Visualizações
Python - Is there a shorthand for [eg]: print(f'type(var) = {type(var)}')

Is there a shorthand in Python for (e.g.) print(f'type(var) = {type(var)}'), without having to state the object in the text and the {.}?

The short answer may be "no", but I had to ask!

E.g. in SAS one may use &= to output a macro variable and its value to the log...

%let macrovar = foobar;  
%put &=macrovar;

which returns in the log: MACROVAR = foobar

This is my first question, and I found it difficult to search for an answer, so apologies if it's been asked and answered.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Indeed there is. As of python 3.8, you can simply type f'{type(var)=}', and you will get the output you desire:

>>> x = {}
>>> f'{x=}'
'x={}'
>>> f'{type(x)=}'
"type(x)=<class 'dict'>"

Further reading:

  1. The "What's New In Python 3.8" page
  2. The documentation for f-strings
  3. The discussion on BPO that led to this feature being implemented.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda