Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Are we running light with overbyte?


devel / comp.lang.python / Re: F-string usage in a print()

SubjectAuthor
o Re: F-string usage in a print()Mats Wichmann

1
Re: F-string usage in a print()

<mailman.474.1653430896.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18371&group=comp.lang.python#18371

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mat...@wichmann.us (Mats Wichmann)
Newsgroups: comp.lang.python
Subject: Re: F-string usage in a print()
Date: Tue, 24 May 2022 16:21:24 -0600
Lines: 21
Message-ID: <mailman.474.1653430896.20749.python-list@python.org>
References: <104490624.2506310.1653426869775.ref@mail.yahoo.com>
<104490624.2506310.1653426869775@mail.yahoo.com>
<e6dfa8b1-18f5-d317-eb19-22238925d575@wichmann.us>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de cuvfPO2TRslmJYG6gEmB1Q5XOWfPZzQkvkaV+XqagWjg==
Return-Path: <mats@wichmann.us>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=pobox.com header.i=@pobox.com header.b=tbTipbhT;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.020
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'argument': 0.04;
'entering': 0.05; 'joining': 0.07; 'string': 0.07; 'implicit':
0.09; 'int': 0.09; 'subject:usage': 0.09; '\\n"': 0.16;
'elsewhere,': 0.16; 'received:64.147': 0.16; 'subject:string':
0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20; 'code': 0.23;
"isn't": 0.27; 'function': 0.27; 'error': 0.29; 'header:User-
Agent:1': 0.30; 'python-list': 0.32; 'header:In-Reply-To:1': 0.34;
'display': 0.36; 'using': 0.37; "it's": 0.37; 'received:192.168':
0.37; 'though': 0.37; 'use': 0.39; 'otherwise,': 0.40; 'above':
0.62; 'skip:m 20': 0.63; 'about.': 0.64; 'number,': 0.64; 'your':
0.64; 'years': 0.65; 'skip:t 20': 0.66; 'received:64': 0.67;
'formatting': 0.76; 'noted': 0.84; 'those,': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=message-id
:date:mime-version:subject:to:references:from:in-reply-to
:content-type:content-transfer-encoding; s=sasl; bh=dAkparbuzx9P
XHeGYiw3OhgD9T1hA+1RJpJ1frPob6E=; b=tbTipbhTqLh9e3pLp4vYIvK2u4WC
+0VQl9N8KGC2QLvIbrO27UDJayCgQoL076WbZlGyhcI0+2efDf5+GccKwcXuVL8G
Qp7TvM7LEVPrDY5j0BF0X8G1J2NRSit66IxsWqBz3Err5EA4y5zvfSqi+gL34Nae
l/9UQL90d36Xkp8=
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=wichmann.us;
h=message-id:date:mime-version:subject:to:references:from:in-reply-to:content-type:content-transfer-encoding;
s=2018-07.pbsmtp; bh=dAkparbuzx9PXHeGYiw3OhgD9T1hA+1RJpJ1frPob6E=;
b=a8WUpqEoynENb/+A3NaMQUbIsW+Y0VoaC//nCjqRBSvXQeDO5G72xnwiHmOkTXn00pblmFrHET2YczaqCZX+HvHWDHSb5yAbWx93UKLU/8ZiUKcfweRqC87O/ox3YXrS+6tFy9jVzzOskAhcQoKeo04zeSQJ3hwE05Kk/vbh8Nw=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Content-Language: en-US
In-Reply-To: <104490624.2506310.1653426869775@mail.yahoo.com>
X-Pobox-Relay-ID: D9A98DFC-DBAF-11EC-ADCB-CB998F0A682E-81526775!pb-smtp2.pobox.com
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <e6dfa8b1-18f5-d317-eb19-22238925d575@wichmann.us>
X-Mailman-Original-References: <104490624.2506310.1653426869775.ref@mail.yahoo.com>
<104490624.2506310.1653426869775@mail.yahoo.com>
 by: Mats Wichmann - Tue, 24 May 2022 22:21 UTC

On 5/24/22 15:14, Kevin M. Wilson via Python-list wrote:
> future_value = 0
> for i in range(years):
> # for i in range(months):
> future_value += monthly_investment
> future_value = round(future_value, 2)
> # monthly_interest_amount = future_value * monthly_interest_rate
> # future_value += monthly_interest_amount
> # display the result
> print(f"Year = ", years + f"Future value = \n", future_value)When joining a string with a number, use an f-string otherwise, code a str() because a implicit convert of an int to str causes a TypeError!Well...WTF! Am I not using the f-string function correctly...in the above line of code???

As noted elsewhere, your f-strings by themselves are fine, it isn't
complaining about those, though they're kind of silly as they don't do
any formatting that justifies entering them as f-strings. It's
complaining about this piece:

years + f"Future value = \n"

which is the second of the three comma-separated argument to print().
That's the int + string the error is grumping about.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor