
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can I concatenate str and int objects in Python?
To concatenate a string with numbers, you need to cast the numbers to string using str(number). For example,
>>> a = "string" >>> b = 1 >>> print a + str(b) string1
In Python 2, you can also use backtick(``) to surround the number and get the same result with numbers and strings. Note that backticks have been removed from Python 3. For example,
>>> a = "string" >>> b = 1 >>> print a + `b` string1
- Related Articles
- Python: Can not understand why I am getting the error: Can not concatenate 'int' and 'str' object
- Python: Cannot understand why the error - cannot concatenate 'str' and 'int' object ?
- How can I concatenate two arrays in java
- How to concatenate a std::string and an int in C++?
- str() vs repr() in Python?
- How can I store JavaScript objects in cookies?
- How can I update child objects in MongoDB?
- Concatenate string to an int value in Java
- How Can You Copy Objects in Python?
- How can I concatenate an array of integer in MongoDB aggregation method?
- How we can convert Python objects into JSON objects?
- How can I update child objects in MongoDB database?
- Explain str() vs repr() functions in Python
- How can I make my custom objects Parcelable?
- How can I make my custom objects Serializable?

Advertisements