En Python, las strings son arrays de bytes que representan caracteres Unicode. Sin embargo, Python no tiene un tipo de datos de caracteres, un solo carácter es simplemente una string con una longitud de 1. Los corchetes [] se pueden usar para acceder a elementos de la string.
Ejemplo:
Python3
# Python program to demonstrate # strings # Assign Welcome string to the variable var1 var1 = "Welcome" # Assign statistics string to the variable var2 var2 = "statistics" # print the result print(var1) print(var2)
Python3
# Python program to demonstrate # string concatenation # Defining strings var1 = "Hello " var2 = "World" # + Operator is used to combine strings var3 = var1 + var2 print(var3)
Python3
# Python program to demonstrate # string concatenation var1 = "Hello" var2 = "World" # join() method is used to combine the strings print("".join([var1, var2])) # join() method is used here to combine # the string with a separator Space(" ") var3 = " ".join([var1, var2]) print(var3)
Python3
# Python program to demonstrate # string concatenation var1 = "Hello" var2 = "World" # % Operator is used here to combine the string print("% s % s" % (var1, var2))
Python3
# Python program to demonstrate # string concatenation var1 = "Hello" var2 = "World" # format function is used here to # combine the string print("{} {}".format(var1, var2)) # store the result in another variable var3 = "{} {}".format(var1, var2) print(var3)
Python3
# Python program to demonstrate # string concatenation var1 = "Hello" var2 = "World" # , to combine data types with a single whitespace. print(var1, var2)
Publicación traducida automáticamente
Artículo escrito por Santhosh220897 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA