Module 2 - Anatomy of a Python Statement Flashcards
(41 cards)
what can python statements do?
Creating data objects
Giving names to data objects
Performing operations on data objects
Use properties of data objects to execute other statements conditionally and/or repeatedly
yypes of python statements
simple statements and compound statements.
simple statement.
one line of code
compound statements.
contain multiple commands or instructions that are dependent on each other in some ways
tokenization
breaking up the statement into so-called tokens.
Tokens
smallest meaningful unit in a Python program. composed of sequences of characters
types of tokens
- Keywords
- Identifiers
- Literals
- Delimiters
- Operators
- Whitespace Tokens
character
alphabet, a number, a punctuation or a symbol like +, *, &, ^, etc.
Keywords
words reserved for a specific purpose
Identifiers
used to refer to objects in memory
features of an identifier
begins w letter or underscore
optionally, continues w letter, digit, or underscore
cannot be a python keyword
is python case-sensitive?
yes. uppercase and lowercase letters are considered different characters.
Literals
used to represent constant, fixed values in your program
types of literals
integer literals
floating point literals
string literals
integer literals
Integer literals are tokens made up of one or more digits and no other characters.
floating point literals
tokens used to represent a real number.
A float literal contains a dot (.) and one or more digits.
string literals
String literals are sequences of characters surrounded by single quotation marks (‘) or double quotation marks (“)
Delimiters
special characters whose functions vary depending on context.
Operators
tokens that perform operations on objects
Whitespace Tokens
three individual Python tokens that do not belong to any token kind.
indent
dedent
newline
parsing
the process of python understanding the program
how does python parse out tokens?
Python reads statements left-to-right and top-to-bottom
Python looks for the longest continuous sequence of tokens possible that can be read as a statement
Whitespace can be used to manually separate tokens
indentation rules
if you indent once, and the next line has the same indentation level, only one indent token will be parsed, the first one
a single line of code can only have one indent token at a time.
a single line of code can have multiple dedent tokens
features of an object
identity, type, value