Python 3 - Beginner Flashcards

1
Q

What is a string?

A

a sequence of characters enclosed by single, double, or triple quotes

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

What is the escape sequence for a new line?

A

\n

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

What are the 2 main types of numbers?

A

Integers (int) and Floats (float)

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

What does the % operator do?

A

Returns the remainder after division of one number by another

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

What does the // operator do?

A

Integer division

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

What does the abs() function do?

A

Returns the distance between the number in parentheses and 0

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

What is a Boolean?

A

A True or False value

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

What does the Not operator do?

A

The Not operator means denying an expression.

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

What is a List?

A

a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Items in a list are enclosed with [ ] brackets

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

What is a set?

A

An unordered collection of unique elements. Sets are enclosed in { } curly brackets

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

What is a tuple?

A

Tuples are immutable lists (their contents cannot be changed by adding, removing, or replacing elements). Tuples are enclosed in ( ) round brackets.

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

What is a frozenset?

A

Frozensets are immutable sets.

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

What are Ranges?

A

The range() function is used to generate a sequence of numbers over time. (start, end, step)

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

What are dictionaries?

A

a dictionary is an unordered set of key value pairs.

dict1 = { “1”: “One”, “2”: “Two”}

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

How do if/elif/else statements operate?

A

code is executed based on one or more conditions being evaluated as True or False. Once conditions are met, the code is run and any code following is ignored.

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

What symbol should follow an if/elif/else statement?

A

a colon :

17
Q

How many spaces should code be indented following an if/elif/else statement?

A

4 (TAB)

18
Q

What is a For loop?

A

a For loop executes a block of code a number of times depending on the sequence it iterates on. The “else” clause is optional.

19
Q

What is the syntax of a for loop?

A

for x in item
x is any temporary variable.
item can be any object including ranges

20
Q

What does the enumerate function do?

A

It allows us to loop over something and have an automatic counter. It also also accepts an optional argument which makes it even more useful.

for counter, value in enumerate(some_list):
print(counter, value)