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

337
Visualizações
In Python, can I specify a range of string indices in a return statement placeholder?

I'm practising using Python's .format method.

The first block of code below can print first_name and the first letter of last_name.

In the second block of code I was experimenting with the index in the second place holder to try and specify a slice of letters to print.

However, I can't get it to work. Is this possible?

def nametag(first_name, last_name):
    return("{} {[0]}.".format(first_name, last_name))

print(nametag("Joe", "Smith")) 
print(nametag("Frank", "Rinaldi")) 
print(nametag("Jean-Luc", "Pierre"))
def nametag(first_name, last_name):
    return("{} {[0:3]}.".format(first_name, last_name))

print(nametag("Joe", "Smith")) 
print(nametag("Frank", "Rinaldi")) 
print(nametag("Jean-Luc", "Pierre"))
over 4 years ago · Santiago Trujillo
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