Python interview questions: string concatenation

Python string test point in interview questions#

There are several ways to connect strings and strings

Answer: 5 kinds

    • Sign (plus sign)
  1. direct connection
  2. format
  3. Connect with a comma (,), redirect standard output
  4. join method
s ="hello""world"print(s)from io import StringIO
import sys
old_stdout = sys.stdout
result =StringIO()
sys.stdout = result
print('hello','world')
sys.stdout = old_stdout #Restore standard output
result_str = result.getvalue()print("Connect with comma: ", result_str)

How to connect between strings and non-strings#

    • number
  1. format
  2. Redirect

How to make the object output specific content when the string is connected with the object, such as Myclass

classMyclass:
 def __str__(self):return'This is a Myclass Instance.'

my =Myclass()
s = s1 +str(my)print(s)

Recommended Posts

Python interview questions: string concatenation
Python interview questions
Python interview questions summary
Python classic interview questions two
Python interview questions collection (three)
Python string
Python string
Python classic programming questions: string replacement
Python answers questions
Python string manipulation
Python interview assault
Str string in Python
How Python converts string case
LeetCode brushing questions summary python3
Python string three formatted output
Python implements string and number splicing
The premise of Python string pooling