Answers for "python function formatting"

1

how to do formatting in python with format function

age = 36
txt = "his age is {}"
print(txt.format(age))
Posted by: Guest on December-22-2021
2

Python string formatting

# String Formatting
name1 = 'Andrei'
name2 = 'Sunny'
print(f'Hello there {name1} and {name2}')       # Hello there Andrei and Sunny - Newer way to do things as of python 3.6
print('Hello there {} and {}'.format(name1, name2))# Hello there Andrei and Sunny
print('Hello there %s and %s' %(name1, name2))  # Hello there Andrei and Sunny --> you can also use %d, %f, %r for integers, floats, string representations of objects respectively
Posted by: Guest on November-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language