Jed Rembold & Fred Agbo
September 25, 2023
{}
placeholder
A = 10.234
print(f"The value of A is {A:0.2f}")
+
sign ensures all numbers will have
either a +
or -
sign in front-
sign in front)<
, >
,
or ^
for left, right, or center
justifiedWhich of the provided formatted string options below would evaluate to appear as:
**101,234.98 & 4000
when printed?
f"{101234.984:*<12,.2f} & {3200//8:1<4d}"
f"{101234.984:*>12,.2f} & {32000//8:1>3d}"
f"{101234.984:*<12,f} & {320//8:1>4d}"
f"{101234.984:*<12,.2f} & {32//8:1<4d}"
english.py
english
library provides two objects
you can import into your programs:
ENGLISH_WORDS
, which is a
list of all the valid words in the English dictionaryis_english_word()
, which
accepts a single string as an argument and returns
True
if the string represents a valid
English word.from english import ENGLISH_WORDS
count = 0
for word in ENGLISH_WORDS:
if len(word) == 2:
count += 1
print(count)
from english import is_english_word
count = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for letter1 in alphabet:
for letter2 in alphabet:
word = letter1 + letter2
if is_english_word(word):
count += 1
print(count)
WordleGWindow
So far, all operations between or on objects have used symbols to indicate the operation
+
sign, for instanceGoing forward, we will begin to see more examples of operations on objects that use receiver syntax
In receiver syntax, we specify the object to act on, followed by a dot and then a predefined function (called a method here) name
obj.method_name()
()
at the
end