Last answered:

11 Oct 2022

Posted on:

09 Oct 2022

0

what's mean the f' in a code ?

in question three why should I add 'f' ' in the last print ?

3 answers ( 0 marked as helpful)
Instructor
Posted on:

10 Oct 2022

0

Hey Alejandro,

Thank you for your question!

Could you please share the name of the file you are reading the exercise from?

Kind regards,
365 Hristina

Posted on:

11 Oct 2022

0

i think that i undestand the use of the 'f' but y want the technical answer. in this case for example:

count = 0
class_names = []
name = input('Please enter name type n to stop:> ')
while name != 'n':  #Cuando se digite n el ciclo para de guardar nombres
   count +=1
   class_names.append(name)
   print(f'{name} has been added.')
   name = input('Next name?:> ')

print(**f'**There are {count} people in the class, they are {class_names}' )

thak'u very much

Instructor
Posted on:

11 Oct 2022

1

Hey Alejandro,

Thank you for the example!

These are the so-called f-strings. Typing an f in front of a string allows you to enter values of variables inside that string by enclosing the variables in curly braces.

In your code, try and change the last line from

print(f'There are {count} people in the class, they are {class_names}')

to

print('There are {count} people in the class, they are {class_names}')

Notice the change? Without the f in front, {count} and {class_names} are just strings. With the f, their values are displayed instead.

Hope this helps!

Kind regards,
365 Hristina

Submit an answer