Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 9 String Interpolation #195

Open
pearcej opened this issue Oct 6, 2021 · 6 comments
Open

Chapter 9 String Interpolation #195

pearcej opened this issue Oct 6, 2021 · 6 comments

Comments

@pearcej
Copy link
Contributor

pearcej commented Oct 6, 2021

The PEP standards include two methods for string interpolation. See https://www.python.org/dev/peps/pep-3101/

Python currently provides two methods of string interpolation:

The '%' operator for strings.

  • The string.Template module which uses .format like
    "My name is {0}".format('Fred')
  • The '%' operator for strings like:
    "My name is %s" % ('Fred')

But perhaps we should be presenting the simpler syntax of f-strings as described in https://www.python.org/dev/peps/pep-0498/ as recommended by @bnmnetp below?

@bnmnetp
Copy link
Member

bnmnetp commented Oct 7, 2021

How many should we show. In my opinion we should be moving toward the future. In fact my preferred method is to teach students f-strings

name = ‘Fred’
print(f”my name is {name}”)

The % operator is still good/interesting to show students as it maps to C/C++/Java but it is definitely not mainstream Python in 2021.

@pearcej
Copy link
Contributor Author

pearcej commented Oct 7, 2021

Very fair point. I have updated my Issue.

@ConceptaNjolima
Copy link

I am working on this issue

@ConceptaNjolima
Copy link

@bnmnetp @pearcej Is the suggestion that we change everywhere the format method is used to using an f-string or only change Activity: 9.5.1.2 ActiveCode?

@bnmnetp
Copy link
Member

bnmnetp commented Nov 28, 2021

I think students should be exposed to all of the various string interpolation types so that they understand what they see when they run across code. But I think we should isolate .format and the old printf style formats to a section and then use fstrings consistently throughout.

@pearcej
Copy link
Contributor Author

pearcej commented Dec 4, 2021

I have been convinced that @bnmnetp is right about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants