WEEK 1 python Flashcards

1
Q

3 + 3 = 6
what are the
values
operator
evaluation

A

3 = values
+ = operator
6 = evaluation

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

what is ‘’//’’

A

integrer division(floor division): 22/8 = 2.75 but we only take 2

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

integers
floating numbers
strings

A

integers (INT): whole numbers (-2, 0, 2)

floating numbers (FLOATS): numbers with decimals (-1.25, 0.5, 1.0)

Strings (STR): text values inside quotes: (‘Hello’, ‘11 cats’)

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

How does + (addition) work for numbers and strings

A

Numbers: adds them (2 + 3 = 5)
Strings: joins them together ‘John’ + ‘Bob’ –> JohnBob

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

How do you add a string and a number

A

(‘Alice’ + str(43)) –> Alice43

you have to convert the number to a string manually.

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

how does multiplication work for numbers and strings

A

Numbers: 4 * 5 = 20

Strings and numbers: ‘Alice’ * 6 –> AliceAliceAliceAliceAliceAliece (repeats the string X times)

you cannot multiply two string together

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

what does a variable do

A

stores a value in memory for later use, you create this by using ‘=’

spam = 40
from now on the variable ‘spam’ now holds 40

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

what is overwriting

A

if yo assign a new variable to a variable, the old value is lost.

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

valid variable names can only use

A

letters, numbers and underscores (_)

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

valid variable names are…

A

cannot start with a number, contain spaces/special characters (like (-, $, @), case sensitive, camelcase can be used (every new word starts with capital letter)

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

what is done with the #

A

nothing, python ignores it, these are just comments for yourself

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

What is the Interactive Shell?

A

A tool that lets you run Python ONE LINE AT A TIME and see results immediately (REPL).

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

What is the File Editor?

A

A tool for writing FULL Python programs, where code is saved in a .py file and run all at once.

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

What is the difference between the Interactive Shell and File Editor?

A

The Interactive Shell runs code instantly (»> prompt), while the File Editor saves and runs entire scripts.

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

Why doesn’t the File Editor run code when you press Enter?

A

Because it is used for writing full programs, not for executing commands line-by-line.

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

What happens when a Python program runs from a file?

A

Python executes the entire script and terminates when there are no more lines of code.

17
Q

commenting out

A

when writing a program, you may want to temporarily disable a line of code without deleting it. Instead of removing the line, you can “comment it out” using #.

18
Q

Functions do something when called.

A

In Python, when you write print(“Hello, world!”), you are calling the print() function.

19
Q

What is input() used for?

A

input() allows the user to type information, making the program interactive.

20
Q

What happens if you hardcode a value? (myName = “Alice”)

A

The program always uses “Alice”—it never changes, no matter who runs it.

21
Q

Why use input() instead?

A

It lets any user enter their own name, making the program dynamic and interactive.

22
Q

What is len() used for?

A

It counts the number of characters in a string, including spaces.

23
Q

What is the output for len(“Alice”)?

A

5 (since “Alice” has 5 characters: A, l, i, c, e)

24
Q

Can you convert a number to a string?

A

Yes! Use str(number) to turn a number into a string.

25
Q

Can you convert a string to a number?

A

Yes! Use int(string) for whole numbers and float(string) for decimals, so only possible with numbers that are treated as words.

26
Q

What does int() do?

A

Converts a decimal number or a string into an integer (whole number).

27
Q

Example of int()?

A

int(1.99) → 1 (Rounds down!)

28
Q

What does float() do?

A

Converts an integer or a string into a decimal (floating-point number).

29
Q

Example of float()? –> float(10)

30
Q

Why does input() return a string?

A

input() always returns text, even if you enter a number

31
Q

'’42’’ is it a number of a string

A

with ‘’ it is a string

32
Q

is this correct 42 == ‘‘42’’

33
Q

how can you change 42 == ‘‘42’’ to the correct version

A

42 == int( ‘‘42’’)

34
Q

is this the same according to python: 42 == 42.0

35
Q

what does python do with extra zeros

A

they ignore them, so 042.000 == 42.0