Basics Flashcards

1
Q

Escape characters

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

String literals can span multiple lines.

A

One way is using triple-quotes: “"”…””” or ‘'’…’’’. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line. The following example:

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

Concatination and repeats

A

the + operator, and repeated with *

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

String indexing

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

String slicing

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

One way to remember how slices work is to think of the indices as pointing . . .

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

String immutability

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

Lists

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

Indexing and Slicing lists

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

Slicing lists

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

Concatinating lists

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

List mutability

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

len()

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

Nesting Lists

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

print()

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

end

A
17
Q

multiple assignment

A

a, b = 0, 1

The variables a and b simultaneously get the new values 0 and 1. On the last line this is used again, demonstrating that the expressions on the right-hand side are all evaluated first before any of the assignments take place. The right-hand side expressions are evaluated from the left to the right.

18
Q

if Statements

A
19
Q

for Statements

A
20
Q

the range() function

A
21
Q

To iterate over elements in a range . . .

A
22
Q

A strange thing happens if you just print a range:

A
23
Q

the break statement

A
24
Q

the continue statement

A
25
Q

pass statements

A
26
Q

Defining functions: def

A

The keyword def introduces a function definition. It must be followed by the function name and the parenthesized list of formal parameters. The statements that form the body of the function start at the next line, and must be indented.

The first statement of the function body can optionally be a string literal; this string literal is the function’s documentation string, or docstring. (More about docstrings can be found in the section Documentation Strings.) There are tools which use docstrings to automatically produce online or printed documentation, or to let the user interactively browse through code; it’s good practice to include docstrings in code that you write, so make a habit of it.

27
Q

Functin execution

A

The execution of a function introduces a new symbol table used for the local variables of the function. More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable references first look in the local symbol table, then in the local symbol tables of enclosing functions, then in the global symbol table, and finally in the table of built-in names. Thus, global variables and variables of enclosing functions cannot be directly assigned a value within a function (unless, for global variables, named in a global statement, or, for variables of enclosing functions, named in a nonlocal statement), although they may be referenced.

28
Q

parameters (arguments)

A

The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object). 1 When a function calls another function, a new local symbol table is created for that call.

29
Q

re-naming mechanism

A
30
Q

It is simple to write a function that returns a list of the numbers of the Fibonacci series, instead of printing it:

A
31
Q
A