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,050 points

edited Dec 12, 2018 by Anirudh 30 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,500 points

edited Dec 12, 2018 by Nymeria

Related Questions In Python

0 votes
1 answer
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 in Python by Sharan
15 views
+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points
1,007 views
0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
1,168 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
54 views
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,500 points

edited Dec 12, 2018 by Nymeria 28 views
0 votes
1 answer

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

You don't need to change your existing ...READ MORE

answered Dec 3, 2018 in Python by Nymeria
• 3,500 points

edited Dec 19, 2018 by Nymeria 4,975 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.