F-Strings vs Format Python 3.X


Python is a high-level programming language use for a lot of people for different pruposes such as: data science, web programming, scripting, ML/AI,etc.

I am going to show you the different ways of concatenating strings in python. Concatenating is easy we just write two differents sentence and we combine them in one line

A variable is a simple data structure that help us to store information in it. We can store a number, a name, an image in a variable. In a variable we can just store one value.If we want to store different variables, we can create different variables with different names or use a different data structure such as list, tuples,dictionaries,etc for store the information

In python we can use the method format for concatenating a string with a variable.In the next example we can see the use of this function with one variable


a=10
print("El numero es {0}".format(a))

Example of concatenating two variables with format()

#Here we declare and assign the values to this two variables in python
a,b=10,20
print("Variable 1 is {0} and the variable 2 is {1}".format(a,b))

Since the version 3.6 of Python we can use the f-Strings.

In pyhton we can use this for concatenating a variable with a string, but for using the f-strings. In the next example we can find the use of this f-strings.

l=int(input("Ingresa el lado del cuadrado"))
a=l**2
print (f"El aerea del cuadrado es {a}")