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

edited Dec 12, 2018 by Anirudh 70 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,540 points

edited Dec 12, 2018 by Nymeria

Related Questions In Python

0 votes
1 answer

How can I write code to find a palindrome in python without using string functions?

In Logic 1, try if i<int(length/2): instead of if i<int((length/2+1)): In ...READ MORE

answered Jan 16, 2019 in Python by charlie_brown
• 7,760 points
5,776 views
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
117 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 4, 2019 in Python by Shabnam
• 920 points
117 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,760 points
2,148 views
0 votes
1 answer
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 752 views
0 votes
0 answers
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,540 points

edited Dec 12, 2018 by Nymeria 101 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,540 points

edited Dec 19, 2018 by Nymeria 24,724 views