Python 3 Print Variables -


is there better way print set of variable in python3 ?

in php useally did this: echo "http://$username:$password@$server:$port"

but in python 3 looks ugly , longer type +'s

print('http://'+username+':'+password+'@'+server+':'+port)

is there in python "$" symbol ? thank you.

python doesn't support string interpolation, can string formatting:

'http://{}:{}@{}:{}'.format(username, password, server, port) 

or keyword arguments (best used if have arguments in dictionary):

'http://{username}:{password}@{server}:{port}'.format(     username=username,     password=password,     server=server,     port=port ) 

you abuse locals() little, wouldn't suggest doing way:

'http://{username}:{password}@{server}:{port}'.format(**locals()) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -