python - cancatenate two strings in a dict -
views.py
def method(request): member in list: personname = {'id':member.id, 'name':member.firstname + member.lastname } return render(request,'some.html',{'name':personname})
in above views.py,i used concatenation operator concatenate firstname , lastname.concatenation happening,i need make space between firstname , lastname.i used " " giving syntax error.
you can use +
concatenating firstname, space , lastname strings:
personname = {'id':member.id, 'name': member.firstname + " " + member.lastname}
or use string formatting:
personname = {'id':member.id, 'name': '%s %s' % (member.firstname, member.lastname)}
or format
:
personname = {'id':member.id, 'name': '{0} {1}'.format(member.firstname, member.lastname)}
Comments
Post a Comment