Sunday 6 April 2014

Manipulating string variable in Python

#!/usr/local/bin/python2.7
   
#Concatenate string
a="This "
b="Python "
c="program "
d="is "
e="about "
f="variable "
resultstr=a+b+c+d+e+f
print(resultstr)

#Repeat string n number of times
str="I will not stop.." * 4
print("\n" + str)
#This is the output : I will not stop..I will not stop..I will not stop..I will not stop..

#Concatenation of Number and string

n=4
m=4.5

s="We can repeat string " + repr(n) + " times but not " + repr(m) + " times"

No comments: