In [2]:
texto = " hola mundo "
print(texto)
print(texto.strip(" "))
texto = " hola mundo "
print(texto)
print(texto.strip(" "))
hola mundo hola mundo
Existen distintas maneras de concatenar un número (INT) y un string (STR)
Para imprimir (print) no es suficiente concatener con +
texto = "hola mundo"
numero = 23
print(texto+numero)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-3fbf59f578f0> in <module>() 1 texto = "hola mundo" 2 numero = 23 ----> 3 print(texto+numero) TypeError: must be str, not int
texto = "hola mundo"
numero = 23
print(texto+str(numero))
hola mundo23
texto = "hola mundo"
numero = 23
print('{}{}'.format(texto,numero))
hola mundo23
public class Main{
public static void main(String arg[]){
String str = "Hola mundo";
int longitud = str.length();
System.out.println("La longitud es "+longitud);
}
}