Module 2 - Anatomy of a Python Statement Flashcards

1
Q

what can python statements do?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

yypes of python statements

A

simple statements and compound statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

simple statement.

A

one line of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

compound statements.

A

contain multiple commands or instructions that are dependent on each other in some ways

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

tokenization

A

breaking up the statement into so-called tokens.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Tokens

A

smallest meaningful unit in a Python program. composed of sequences of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

types of tokens

A
  1. Keywords
  2. Identifiers
  3. Literals
  4. Delimiters
  5. Operators
  6. Whitespace Tokens
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

character

A

alphabet, a number, a punctuation or a symbol like +, *, &, ^, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Keywords

A

words reserved for a specific purpose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Identifiers

A

used to refer to objects in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

features of an identifier

A

begins w letter or underscore
optionally, continues w letter, digit, or underscore
cannot be a python keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

is python case-sensitive?

A

yes. uppercase and lowercase letters are considered different characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Literals

A

used to represent constant, fixed values in your program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

types of literals

A

integer literals
floating point literals
string literals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

integer literals

A

Integer literals are tokens made up of one or more digits and no other characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

floating point literals

A

tokens used to represent a real number.

A float literal contains a dot (.) and one or more digits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

string literals

A

String literals are sequences of characters surrounded by single quotation marks (‘) or double quotation marks (“)

18
Q

Delimiters

A

special characters whose functions vary depending on context.

19
Q

Operators

A

tokens that perform operations on objects

20
Q

Whitespace Tokens

A

three individual Python tokens that do not belong to any token kind.

indent
dedent
newline

21
Q

parsing

A

the process of python understanding the program

22
Q

how does python parse out tokens?

A

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

23
Q

indentation rules

A

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

24
Q

features of an object

A

identity, type, value

25
Q

what is the identity of an object? how can you find it?

A

refers to the location where it is stored in the computer memory.

You can find the identity of an object by using the id function.

26
Q

what is the type of an object? how can you find it?

A

determines the kinds of operations that are performed on it and how it can be stored in memory.

You can find the type of an object by using the type function.

27
Q

what is the value of an object

A

The value of an object determines the memory contents for each particular object of a certain type.

28
Q

can Two distinct objects have the same type, value, and identity?

A

Two distinct objects can have the same type and the same value—but they will always have different identities.

29
Q

list vs tuple

A

while tuples are immutable objects, lists are mutable (can be changed)

lists are square brackets.

30
Q

types of simple statements

A

assignment statement
expression statement
import statement

31
Q

assignment statement

A

allow us to give names to objects in memory

32
Q

expression statement

A

piece of code that can be evaluated to produce a value

33
Q

import statement

A

allows us to gain access to different modules with specific functionalities

34
Q

Types of expression statements

A

atomic expression
attribute reference
subscription operation
unary + binary
slicing
function call

35
Q

atomic expression

A

a piece of code that has a value and cannot be broken down into smaller pieces.

> > > 42

> > > x = 1
x

> > > [1,2,3]

36
Q

Function Calls

A

represent computations or operations on objects that are commonly used in programs. Rather than writing the same lines of code repeatedly for a single computation, we can call the function that does it all for us in one line.

ex: print

37
Q

Subscription Operations

A

used to select an element from a list, string, or tuple.

This is achieved by specifying the index or position of the item within a sequence. We always start counting from 0.

> > > “Hello World!”[0]
‘H’

38
Q

Slicing

A

Slicing allows us to select a range of items or characters from a sequence, such as a string, list, or tuple.

> > > “catfish”[0:3]
‘cat’

39
Q

> > > “catfish”[0:3]
‘cat’

why does it return ‘cat’ and not ‘catf’?

A

0 does refer to the first item in the sequence

40
Q

Attribute Reference

A

Some objects in Python have so-called attributes. This can be seen in modules. Modules may contain functions and constants, which are considered attributes of that specific module.

41
Q
A