Week 6 - Python Flashcards

1
Q

How to run a Python program?

A

python programName.py

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

What are some of biggest differences between Python and C that make Python way cleaner?

A
  • No semicolons at the end of lines
  • No curly braces on blocks
  • No parenthesis on conditionals
  • No type mentioning on vars. declarations/initilializations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to declare a function on Python?

A

def functionName()

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

What should always be the very last line of code of any Python program?

A

Main call - main()

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

What’s the downside of Python being so much easier to program than C, i.e.?

A

Expense of performance, because of so many functions running in the background

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

What’s the comments markup in C?

A

#

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

What are the loops that can be used in Python?

A

While loops and for loops

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

What are lists in Python?

A

Arrays

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

What’s the biggest advantage of Python’s lists?

A

They’re not size fixed

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

What’s the lists markup on Python?

A

Square brackets

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

What are tuples?

A

They’re a data type in Python similar to C’s structs, but they have inmutable values

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

What are objects in Python?

A

They’re similar to C structs

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

Why styling is even more important in Python?

A

Because if tabs and indentation are not used things may not work as intended

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

import fileName in Python is the equivalent to what in C?

A

include <file_name></file_name>

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

What should be used instead of || and && operators in Python?

A

Or/and

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

What should be used instead of else if in Python?

A

elif

17
Q

What to use instead of the bang operator (!) in Python?

A

The keyword not

18
Q

How to write the increment by one operator in Python?

A

+= 1

19
Q

Write a range function

A

for x in range(100):
print(x)

20
Q

What does the range function do?

A

Iterates until the stop condition passed as an argument - 1

21
Q

What are dictionaries?

A

Dictionaires are like hash tables in C. They have key-value pairs

22
Q

What’s the markup for dictionaires in Python?

A

Curly braces

23
Q

What are methods?

A

Functions that can only be called on objects

24
Q

How to add keys and values to dictionaries?

A

book[“title”] = “Corduroy”

25
Q

How are libraries called in Python?

A

Modules

26
Q

What’s the advantage of using with open(“fileName.ext”) as file?

A

Not having to close the file, because Python will do it automatically