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

A

if

22
Q

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

A

else

23
Q

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

A

elif

24
Q

Function to check if a string is only letters

A

.isalpha()

25
Q

Defining a function

A

def

26
Q

Define Function definition

A

Setting up a function which can then be used repeatedly

27
Q

3 Components of a Function

A
  1. header
  2. comment (optional)
  3. body
28
Q

Function header format

A

def ():

29
Q

Function Header example

A

def hello_world():

30
Q

Function comment example

A

“””Prints ‘Hello World!’ to the console”””

31
Q

Running a function example

A

hello_world()

32
Q

Parameter definition

A

a variable that is an input to a function

33
Q

Parameter example

A

n in def square(n):

34
Q

Argument definition

A

The value of the parameter passed into a function

35
Q

Argument example

A

10 in square(10)

36
Q

Function to import a certain function from a module

A

from import

37
Q

Importing certain function from a module example

A

from math import sqrt

38
Q

Function to import all variables and functions from a module

A

from import *

39
Q

Importing all variables and functions from a module example

A

from math import *

40
Q

Function that takes any number of arguments and returns the largest one

A

max()

41
Q

Taking any number of arguments and returning the largest one example

A

max(1,2,3)

3

42
Q

Function that returns the smallest of the arguments

A

min()

43
Q

Returning the smallest argument example

A

min(1,2,3)

1

44
Q

Function that returns the absolute value of its argument

A

abs()

45
Q

Returning the absolute value of its argument example

A

abs(-42)

42

46
Q

Function that returns the type of data it receives as an argument

A

type()

47
Q

Returning the type of data it receives as an argument example

A

type(42)

int

48
Q

Function that deletes an item from a list

A

.remove()

49
Q

Function to remove an item at a certain index from a list

A

.pop()