Codecademy Python 1 Flashcards

1
Q

Float definition

A

a number with a decimal

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

Integer definition

A

a number with no decimal

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

How to yield a float instead of an integer

A

Change either a numerator or denominator to be a float (add a period)

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

Yielding a float example

A

quotient 1 = 7./2

quotient 2 = 7/2.

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

The float method example

A

quotient 1 = float(7)/2

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

Operator for combining a string with variables

A

“%s” % ()

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

Combining string with variables example

A

name = “Mike”

print “Hello %s” % (name)

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

Operator for combining a string with variables python 3

A

”{}” .format ()

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

Combining strings with variables example Python 3

A

name = “Mike”

print (“Hello {}”.format (name))

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

Padding a variable with zeroes

A

%02d

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

Function to print the date and time in a nice format

A

datetime

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

Importing datetime

A

from datetime import datetime

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

Program to print the current date and time

A

now = datetime.now()

print now

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

Equal to

A

==

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

Not equal to

A

!=

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

Less than

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

Less than or equal to

A

<=

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

Greater than

A

>

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

Greater than or equal to

A

> =

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

Order of operations for Boolean operators

A

not, and, or

21
Q

A conditional statement that does something after seeing if its expression is True

22
Q

A statement that is run if the “if” statement is false

23
Q

A statement that runs if the previous expression is false but the following statement is true

24
Q

Function to check if a string is only letters

A

.isalpha()

25
Defining a function
def
26
Define Function definition
Setting up a function which can then be used repeatedly
27
3 Components of a Function
1. header 2. comment (optional) 3. body
28
Function header format
def ():
29
Function Header example
def hello_world():
30
Function comment example
“””Prints ‘Hello World!’ to the console”””
31
Running a function example
hello_world()
32
Parameter definition
a variable that is an input to a function
33
Parameter example
n in def square(n):
34
Argument definition
The value of the parameter passed into a function
35
Argument example
10 in square(10)
36
Function to import a certain function from a module
from import
37
Importing certain function from a module example
from math import sqrt
38
Function to import all variables and functions from a module
from import *
39
Importing all variables and functions from a module example
from math import *
40
Function that takes any number of arguments and returns the largest one
max()
41
Taking any number of arguments and returning the largest one example
max(1,2,3) | 3
42
Function that returns the smallest of the arguments
min()
43
Returning the smallest argument example
min(1,2,3) | 1
44
Function that returns the absolute value of its argument
abs()
45
Returning the absolute value of its argument example
abs(-42) | 42
46
Function that returns the type of data it receives as an argument
type()
47
Returning the type of data it receives as an argument example
type(42) | int
48
Function that deletes an item from a list
.remove()
49
Function to remove an item at a certain index from a list
.pop()