How to put a variable inside a String using Python

0 votes

I want to put an int into a string. This is what I had in mind:

end = smooth(data,window_len=40)
plot.plot(time[0:len(end)],end)
plot.savefig('hanning(40).pdf') #problem line

How do I insert a variable into a Python string as stated? Appreciate the help!
Nov 23, 2018 in Python by Anirudh
• 2,090 points

edited Dec 12, 2018 by Anirudh 1,198 views

1 answer to this question.

0 votes

In the easiest way, you can create strings using:

stringExample = "someString " + str(someNumber)
print(stringExample)
plot.savefig(stringExample)

Hope this helps!

answered Nov 23, 2018 by Nymeria
• 3,560 points

edited Dec 12, 2018 by Nymeria

Related Questions In Python

0 votes
1 answer

How to check if a substring is present in a string using Python?

To check if the substring exists in ...READ MORE

answered May 9, 2019 in Python by Sharan
1,128 views
+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 5, 2019 in Python by Shabnam
• 930 points
2,019 views
0 votes
1 answer

How to reverse a string in Python using slicing operator?

Hi@akhtar, Strings can be reversed using slicing. To ...READ MORE

answered Aug 17, 2020 in Python by MD
• 95,460 points
3,752 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,422 views
0 votes
1 answer
0 votes
1 answer

How to convert an integer to a string using Python?

Here is an easy solution: def numberToBase(n, b): ...READ MORE

answered Nov 23, 2018 in Python by Nymeria
• 3,560 points

edited Dec 12, 2018 by Nymeria 1,154 views
0 votes
3 answers

How to get the return value from a thread using python?

FWIW, the multiprocessing module has a nice interface for ...READ MORE

answered Dec 15, 2020 in Python by Roshni
• 10,480 points
107,695 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP