Skip to content

Instantly share code, notes, and snippets.

@BurhanH
Created February 25, 2019 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BurhanH/cbb95c9c5d1c69833dbca0bbecf9ef6c to your computer and use it in GitHub Desktop.
Save BurhanH/cbb95c9c5d1c69833dbca0bbecf9ef6c to your computer and use it in GitHub Desktop.
string interpolation 2, Python 3.6 and above
# -*- 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