How to append an integer to a string?

+1 vote

I have an integer and I have a string. Now I want to create a new string which is got by concatenated the string and the integer. But I don’t understand how to do this?

I am using this following code:

a = 10

new = “hello” + a

But I get this error:

File "program.py", line 2,

new = “hello” + a

TypeError: Can't convert 'int' object to str implicitly
Aug 16, 2018 in Python by ana1504.k
• 5,950 points
35 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

You can not directly concatenate two different data-types. You have to type-cast it first.

Try this code:

name = 'b' + str(num)

or

name = 'b%s' % num
answered Aug 16, 2018 by Omkar
• 65,840 points

Related Questions In Python

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 22 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,020 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by ariaholic
• 7,320 points
47 views
0 votes
1 answer

How do you append to a file?

with open("test.txt", "a") as myfile: myfile.write("appended text" ...READ MORE

answered Jul 27, 2018 in Python by Priyaj
• 56,120 points
18 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
20 views
+4 votes
6 answers
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 65,840 points

edited Aug 8, 2018 by Omkar 271 views
+1 vote
2 answers

How to convert list to string

mylist = [1, 2, 3] ‘’.join(map(str, mylist)) ==> ...READ MORE

answered Aug 21, 2018 in Python by Omkar
• 65,840 points
26 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.