Jump to content

Python: Difference between revisions

450 bytes added ,  10 October 2019
Line 11: Line 11:
is_nice = True
is_nice = True
state = "nice" if is_nice else "not nice"
state = "nice" if is_nice else "not nice"
</syntaxhighlight>
===Strings===
====String Interpolation====
[https://www.programiz.com/python-programming/string-interpolation Reference]
Python has 3 syntax variations for string interpolation.
<syntaxhighlight lang="python">
name = 'World'
program = 'Python'
print(f'Hello {name}! This is {program}')
print("%s %s" %('Hello','World',))
name = 'world'
program ='python'
print('Hello {name}!This is{program}.'.format(name=name,program=program))
</syntaxhighlight>
</syntaxhighlight>