Python Flashcards

1
Q

How do you print an entire array?

A

for n in #data name#:
print(str(n));

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

How about length of an array

A

len(##data name))

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

What is a function and what should I know about?

A

this is a function

def <name>(<variable name)</name>

with a bunch of math or conditions after indented.

for example

def get_pay(num_hours):
receiving $15/hour
pay_pretax = num_hours * 15
pay_aftertax = pay_pretax * (1 - .12)
return pay_aftertax

Now if I want to recall it, I just do get_pay(40) for eg.

Note: you cannot refer to the variable within the function body.

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

Why should I use a function with no argument?

A

If you don’t want a dynamic function and want to show the same answer over and over without having to type it, you can use function with no argument.

for example

def greeting_message()
print(“Hello”)
print(“How are you?”).

now every time you greeting_message()

it will print the message.

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

What are the symbols used in a conditional statement (if, elif…)?

A

Symbol Meaning

== : equal

!= : does not equal

< : less than

<= less and equal than

> : greater than

> = greater and equal than

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