Answers for "string formatting python %s"

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
1

formatted string in python

>>> name = "world"
>>> print(f"Hello {name}!)"
'Hello world!'
Posted by: Guest on December-18-2020

Python Answers by Framework

Browse Popular Code Answers by Language