How to concatenate or delete variables?

969    Asked by HellenCargill in Data Science , Asked on Jan 12, 2020
Answered by Hellen Cargill

 In python, you can concatenate two variables with each other and if both variables are the same type then its easy to concatenate but if one is numeric and the other is a string then before concatenating you must convert numeric variable as a string. Please see below example for better understanding:

#Declaring a variable

a = "janbask"

b = "Training"

print(a+b)

If you run the above code it will give output “janbaskTraining


#Declaring a variable

a = "janbask"

b = 100

c = a+b

print(c)

If you run above code in python you will get an error because both variables are different type, refer below code now:

#Declaring a variable

a = "janbask"

b = 100

c = a+str(b)

print(c)

If you want to delete any variable use “del” keyword like below:

del a

This will delete variable a.



Your Answer

Interviews

Parent Categories