You are on page 1of 15

Welcome to English

Programming

Week 4 Class 1

Student Worksheet
Materials for the class
Part 1. Language Skills
[Capte la atención de los lectores mediante una cita importante extraída del documento o utilice este espacio
para resaltar un punto clave. Para colocar el cuadro de texto en cualquier lugar de la página, solo tiene que
arrastrarlo.]
Shuroop

Khalal Lian
Michell

Khalal Lian
Shuroop Camille
Shuroop

Erdal
Practice
More Practice
Part 2. Reading
BEFORE READING

1. Vocabulary
You will read about STRINGS, and the following words (wordcloud) appear in the text. Understanding those
words will help understand better the text, so complete the exercises below.

1. Parts of speech.
a. The words in blue are _____verbs________.
b. The words in red are _____________.
c. The words in pink are _____________.

2. Which of those words are cognates?


COGNATES
CONVERSION
3. Complete the chart to form word families.

verb noun adjective adverb


_____________ replacement _____________ ------

_____________
define _____________ _____________ ------
_____________ Specification _____________ _____________

_____________
_____________ value _____________ ------

2. Scanning
Complete the following ideas with words taking from the text below.
a. string.hexdigits, string.octdigits, and string.punctuation are constants in the module about
strings.
b. With the Formatter class you can create/customize your personal string formatting behavior.
c. Replacement fields are part of format strings.

WHILE READING
Now, it is time to read about STRINGS. Read the text and answer the questions. You can find the text in the
following link: string — Common string operations — Python 3.9.4 documentation
string — Common string operations
1. String constants. The constants defined in this module are:
a. string.ascii_letters
b. string.ascii_lowercase
c. string.ascii_uppercase
d. string.digits
e. string.hexdigits
f. string.octdigits
g. string.punctuation
h. string.printable
i. string.whitespace
2. Custom String Formatting.
a. The built-in string class provides the ability to do complex variable substitutions and value
formatting via the format() method described in PEP 3101. La clase de cadena incorporada
proporciona la capacidad de realizar sustituciones de variables complejas y formateo de valores a
través del método format () descrito en PEP 3101.
b. The Formatter class in the string module allows you to create and customize your own string
formatting behaviors using the same implementation as the built-in format() method. La clase
Formatter en el módulo de cadena le permite crear y personalizar sus propios comportamientos de
formato de cadena utilizando la misma implementación que el método integrado format ().
c. class string.Formatter The Formatter class has the 8 public methods.
3. Format String Syntax.
(Paragraph 1) The str.format() method and the Formatter class share the same syntax for format strings
(although in the case of Formatter, subclasses can define their own format string syntax). The syntax is
related to that of formatted string literals, but it is less sophisticated and, in particular, does not support
arbitrary expressions. El método str.format () y la clase Formatter comparten la misma sintaxis para
cadenas de formato (aunque en el caso de Formatter, las subclases pueden definir su propia sintaxis de
cadena de formato). La sintaxis está relacionada con la de los literales de cadena formateados, pero es
menos sofisticada y, en particular, no admite expresiones arbitrarias.
(Paragraph 2) Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is
not contained in braces is considered literal text, which is copied unchanged to the output. If you need to
include a brace character in the literal text, it can be escaped by doubling: {{ and }}. Las cadenas de
formato contienen "campos de reemplazo" rodeados por llaves {}. Todo lo que no esté contenido entre
llaves se considera texto literal, que se copia sin cambios en la salida. Si necesita incluir un carácter de
llave en el texto literal, se puede escapar doblando: {{y}}.
(Paragraph 3) The grammar for a replacement field is as follows:

(Paragraph 4) In less formal terms, the replacement field can start with a field_name that specifies the
object whose value is to be formatted and inserted into the output instead of the replacement field. The
field_name is optionally followed by a conversion field, which is preceded by an exclamation point '!', and a
format_spec, which is preceded by a colon ':'. These specify a non-default format for the replacement
value. En términos menos formales, el campo de reemplazo puede comenzar con un field_name que
especifica el objeto cuyo valor se formateará e insertará en la salida en lugar del campo de reemplazo. El
field_name está opcionalmente seguido por un campo de conversión, que está precedido por un signo de
exclamación '!', Y un format_spec, que está precedido por dos puntos ':'. Estos especifican un formato no
predeterminado para el valor de reemplazo.

(Paragraph 5) The field_name itself begins with an arg_name that is either a number or a keyword. If it’s a
number, it refers to a positional argument, and if it’s a keyword, it refers to a named keyword argument. If
the numerical arg_names in a format string are 0, 1, 2, … in sequence, they can all be omitted (not just
some) and the numbers 0, 1, 2, … will be automatically inserted in that order. Because arg_name is not
quote-delimited, it is not possible to specify arbitrary dictionary keys (e.g., the strings '10' or ':-]') within a
format string. The arg_name can be followed by any number of index or attribute expressions. An
expression of the form '.name' selects the named attribute using getattr(), while an expression of the form
'[index]' does an index lookup using __getitem__(). El field_name en sí mismo comienza con un arg_name
que es un número o una palabra clave. Si es un número, se refiere a un argumento posicional, y si es una
palabra clave, se refiere a un argumento de palabra clave con nombre. Si los arg_names numéricos en
una cadena de formato son 0, 1, 2, ... en secuencia, todos pueden omitirse (no solo algunos) y los
números 0, 1, 2, ... se insertarán automáticamente en ese orden. Debido a que arg_name no está
delimitado por comillas, no es posible especificar claves de diccionario arbitrarias (por ejemplo, las
cadenas '10' o ': -]') dentro de una cadena de formato. El nombre_arg puede ir seguido de cualquier
número de expresiones de índice o atributo. Una expresión de la forma '.name' selecciona el atributo
nombrado usando getattr (), mientras que una expresión de la forma '[index]' realiza una búsqueda de
índice usando __getitem __ ().
(Paragraph 6) The conversion field causes a type coercion before formatting. Normally, the job of
formatting a value is done by the __format__() method of the value itself. However, in some cases it is
desirable to force a type to be formatted as a string, overriding its own definition of formatting. By
converting the value to a string before calling __format__(), the normal formatting logic is bypassed. El
campo de conversión provoca una coerción de tipo antes de formatear. Normalmente, el trabajo de
formatear un valor se realiza mediante el método __format __ () del valor en sí. Sin embargo, en algunos
casos es deseable forzar que un tipo sea formateado como una cadena, anulando su propia definición de
formato. Al convertir el valor en una cadena antes de llamar a __format __ (), se omite la lógica de formato
normal.
(Paragraph 7) Three conversion flags are currently supported: '!s' which calls str() on the value, '!r' which
calls repr() and '!a' which calls ascii(). Actualmente se admiten tres indicadores de conversión: '! S' que
llama a str () en el valor, '! R' que llama a repr () y '! A' que llama a ascii ().
(Paragraph 8) The format_spec field contains a specification of how the value should be presented,
including such details as field width, alignment, padding, decimal precision and so on. Each value type can
define its own “formatting mini-language” or interpretation of the format_spec. El campo format_spec
contiene una especificación de cómo se debe presentar el valor, incluidos detalles como el ancho del
campo, la alineación, el relleno, la precisión decimal, etc. Cada tipo de valor puede definir su propio "mini-
lenguaje de formato" o interpretación de format_spec.
(Paragraph 9) Most built-in types support a common formatting mini-language, which is described in the
next section. La mayoría de los tipos integrados admiten un minilenguaje de formato común, que se
describe en la siguiente sección
(Paragraph 10) A format_spec field can also include nested replacement fields within it. These nested
replacement fields may contain a field name, conversion flag and format specification, but deeper nesting is
not allowed. The replacement fields within the format_spec are substituted before the format_spec string is
interpreted. This allows the formatting of a value to be dynamically specified. Un campo format_spec
también puede incluir campos de reemplazo anidados dentro de él. Estos campos de reemplazo anidados
pueden contener un nombre de campo, un indicador de conversión y una especificación de formato, pero
no se permite un anidado más profundo. Los campos de reemplazo dentro de format_spec se sustituyen
antes de que se interprete la cadena format_spec. Esto permite especificar dinámicamente el formato de
un valor.
4. Format Specification Mini-Language
“Format specifications” are used within replacement fields contained within a format string to define how
individual values are presented (see Format String Syntax and Formatted string literals). They can also be
passed directly to the built-in format() function. Each formattable type may define how the format
specification is to be interpreted. Las “especificaciones de formato” se utilizan dentro de los campos de
reemplazo contenidos en una cadena de formato para definir cómo se presentan los valores individuales
(consulte Sintaxis de cadena de formato y Literales de cadena formateados). También se pueden pasar
directamente a la función integrada format (). Cada tipo formateable puede definir cómo se interpretará la
especificación de formato.
1. Meaning from context
a. Match the words with their corresponding meaning.

WORD DEFINITION

a. String (n) _____ 1. (n) the distance across something from one side to the other;
extension

b. Customize (v) _____ 2. (n) The space between the inside edge of a child element and its
(PART 2) content.

c. Behavior (n) _____ 3. (n) A value that a function or a method uses to perform
(PART 2) operations or calculations. It is specific to the function or
method. They include numbers, text, cell references, and names.

d. Syntax (n) _____ 4. (adj) embedded


(PART 3)

e. Argument (n) _____ 5. (v) personalize


(PART 3, paragraph 5)

f. Width (n) _____ 6. (n) a particular way of acting


(PART 3, paragraph 8)

g. Padding _____ 7. (n) A group of characters or character bytes handled as a single


(PART 3, paragraph 8) entity.

h. Nested (adj) _____ 8. (n) The rules governing the formation of a command-line
(PART 3, paragraph 10) statement, including the order in which a command must be
typed, and the elements that follow the command.

b. Based on the information from the text, answer the following questions.
i. What are ‘braces’? _____
ii. What is ‘exclamation point’? _____

iii. What is ‘colon’? _____


2. Reading comprehension
Based on the information from the text, decide if the following sentences are true (T) or false (F).
a. When you copy to the output anything considered literal text, this does not change. T/F
b. To format and insert the value of an object into the output you use the replacement field only. T/F
c. A field name, conversion flag, and format specification can be found in replacement fields, and you can
embed more information. T/F
d. You use ‘format specifications’ to determine the type of presentation of individual values. T/F

You might also like