Python String formatting

Playing With String in Function of Python

def takData(input_data):
   return ("Hi my name is: {}".format(input_data))



input_data=input("Enter your name: ")
print(takData(input_data))

With First letter capital:

def takData(input_data):
   return ("Hi my name is: {}".format(input_data).title())


input_data=input("Enter your name: ")
print(takData(input_data))

Converting string to int:

def takData(input_data):
   return ("Hi my name is: {}".format(input_data).title())



input_data=int(input("Enter your name: "))
print(takData(input_data))

For Python 1 and 2

def takData(input_data):
   return ("Hi my name is: %s" %input_data.title())



input_data=(input("Enter your name: "))
print(takData(input_data))

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *