Created
February 25, 2019 21:49
-
-
Save BurhanH/cbb95c9c5d1c69833dbca0bbecf9ef6c to your computer and use it in GitHub Desktop.
string interpolation 2, Python 3.6 and above
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def hello(name, question): | |
return f"Hello, {name},! How is it {question}?" | |
hello('Stranger', 'going') | |
#"Hello, Stranger! How is it going?" | |
# Similar approach | |
# def hello(name, question): | |
# return("Hello, " + name + "! How is it " + question + "?") | |
# disassemble function | |
import dis | |
dis.dis(hello) | |
# 2 0 LOAD_CONST 1 ('Hello, ') | |
# 2 LOAD_FAST 0 (name) | |
# 4 FORMAT_VALUE 0 | |
# 6 LOAD_CONST 2 ("! How is it ") | |
# 8 LOAD_FAST 1 (question) | |
# 10 FORMAT_VALUE 0 | |
# 12 BUILD_STRING 4 | |
# 14 RETURN_VALUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment