I come from .NET world.
In python code I have database connection string. Is there any way to keep these connection strings encrypted within python code?
Securing the DB configuration or any sensitive configurations can be done by keeping configs encrypted. In python you can do it using packages like secureconfig or encrypted-config or DIY with some standard encryption techniques. 
Keeping the encryption keys outside is the next challenge, which you can tackle by making it a injected config via environmental variables or a command-line-parameter.
Encrypting db connection string