Basics Flashcards

Remember Python controls

1
Q

What does a variable do?

A

Stores a piece of data and gives it a name, to be recalled in a script.

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

What is a boolean?

A

Data type that can only be True or False.

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

#

A

One-lined comment

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

”””

A

”"”Multi-line comment”””

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
addition
subtraction
multiplication
division
exponent
modulo (remainder from division)
A
\+
-
*
/
**
%
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

str()

A

Data type that can contain letters, numbers, and symbols. Strings are in “quotation marks”.

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

Correct the string: ‘There’s a man in my pants!’

A

‘There's a man in my pants!’

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

[index]

A

The assigned number for characters in a string. First number is 0.

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

len()

A

Gets the length (number of characters) in a string.

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

lower()

A

Makes entire string lowercase.

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

upper()

A

Makes entire string uppercase.

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

str()

A

Turns variable into a string.

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

len(lion) and str(lion) but…

A

lion.upper() and lion.lower()

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

Example of concatenation

A

print “Heaven” + “and” + “Hell”

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

print “%s doesn’t know that %s is out to get %s!” % (“Bob”, “Evan”, “Chris”)

A

Bob doesn’t know that Evan is out to get Chris!

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

Retrieve date and time

A

from datetime import datetime

print datetime.now()

17
Q

Print date and time in mm/dd/yyyy format

A

rom datetime import datetime
now = datetime.now()
print ‘%s/%s/%s’ % (now.month, now.day, now.year)

18
Q

==
!=
<

> =

A
equal to
not equal to
less than
less than or equal to
greater than
greater than or equal to
19
Q

‘and’ boolean operator

A

True and True is True
True and False is False
False and True is False
False and False is False

20
Q

‘or’ boolean operator

A

True or True is True
True or False is True
False or True is True
False or False is False

21
Q

‘not’ boolean operator

A

Not True is False

Not False is True

22
Q

Order of boolean operators

A
  1. not
  2. and
  3. or
23
Q
Correct this:
def greater_less_equal_5(answer)
    if (answer > 5)
        return 1
    elif (answer
A
def greater_less_equal_5(answer):
    if (answer > 5):
        return 1
    elif (answer
24
Q

slice into “and”:

s = “Sandra”

A

s = “Sandra”

print s[1:3]

25
header
def function(parameter):
26
functions can...
print text, do math, call another function
27
function import
from math import sqrt
28
universal import
from math import *
29
print everything in a math module
from math import * everything = dir(math) print everything
30
``` functions for: maximum minimum absolute value type ```
max() min() abs() type()
31
What does the dictionary function do?
accesses values by looking up a key instead of an index