0

C++

std::cout << "Hello world!"; // output: Hello world! 

Python

print("Hello world!") # output: Hello world! 

That works. But how can I do this in Python?

std::string name = "Robert"; std::cout << "Hello " << name << ", how are you?"; 
0

3 Answers 3

6

Just use commas to seperate arguments:

print("Hello ", name, ", how are you?", sep='') 

You can also use the f string formatter:

print(f"Hello {name}, how are you?") 

or also with str.format():

print("Hello {}, how are you?".format(name)) 
Sign up to request clarification or add additional context in comments.

Comments

2

You can try this:-

name = 'Robert' print(f'Hello {name}, how are you?') OR print('Hello ', name, ', how are you?', sep='') 

Output:-

Hello Robert, how are you? 

Comments

-1
name = 'Robert' print('Hello ', name,', how are you?',sep = '') 

sep - separator parameter, which will eliminate the space between name and comma.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.