Variables, Data Types, Inputs, and Outputs

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/44

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:33 PM on 9/7/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

45 Terms

1
New cards

What does Python do with anything after the pound (#) sign?

It ignores it

2
New cards

Benefits of writing comments in Python

  • Understand the code that was written at a later time

  • Helps others to read the code

  • Temporarily “comment out” code instead of deleting it


3
New cards

Variable

A name that refers to a value in the computer's memory

4
New cards

What does the assignment operator (=) do?

The name on the left gets the value on the right

5
New cards

How should “=” be read in Python?

  • “Gets”

  • Compute the right side first and then attach the name to the result


6
New cards

What must happen before you can use a variable?

You must assign a value before you use it

7
New cards

What happens when you reassign a variable?

Reassigning replaces the old value

8
New cards

If count = 10, what does count = count + 1 do?

The right side is computed first as 11, then count gets 11

9
New cards

What does count =+ 1 mean?

It is shorthand for count = count + 1

10
New cards

Other shorthand assignment operators introduced

  • -=

  • *=

  • /=


11
New cards

What naming rules does Python enforce for variables?

  • Start with a letter or underscore

  • No spaces

  • No $, #, or @ symbols

  • Cannot start with numbers

  • Variable names are case-sensitive

  • Python keywords cannot be used


12
New cards

What naming conventions were introduced for variables?

  • snake_case (name_of_variable)

  • CamelCase (Name of Variable)


13
New cards

Why is pet_name better than thenameofpet?

It’s shorter, easier to scan, and harder to mistype

14
New cards

What data type is used for whole numbers (integers)?

Int — used for counting and when fractions cannot occur

15
New cards

What data type is used for fractional numbers (decimals)?

float — used for measurements and money

16
New cards

True or False: You do not declare the data type of a variable in Python. Python decides it from the value you assign.

True

17
New cards

String

A sequence of characters (letters, digits, symbols) treated as one unit

18
New cards

What is the data type for a string?

str

19
New cards

How must string literals be written?

They must be wrapped in matching quotes, either ‘ ‘ or “ “

20
New cards

Concatenation

Joining two or more strings with +

21
New cards

What are the two jobs of the + symbol?

  • Adds numbers

  • Joins strings


Which one happens depends on the type

22
New cards

What does the type() function do?

It tells you what Python thinks a value is

23
New cards

Why is year = “2023” a string rather than a number?

The quotes decide, not the characters inside

24
New cards

When code behaves strangely, what is almost always the fastest first move?

Check type()

25
New cards

What do int(), float(), and str() do?

They build a new value of the requested type

26
New cards

What is the result of “5” + “3” and why?

“53” because the two values are strings and are joined together

27
New cards

What is the result of “5” * 3

“555” — the string is repeated three times

28
New cards

Why would int(year) + 1 work if year = “2023”?

int(year) converts the string to an integer first, then Python can do the math

29
New cards

When can conversion between types fail?

When the value cannot be converted to the requested type. For example, float(“abc”) raises a ValueError because the text has to look like a number

30
New cards

What data type does everything typed by a user arrive as?

A string (str)

31
New cards

//

Integer Division

32
New cards

**

Exponent

33
New cards

%

Remainder

34
New cards

Order of Precedence for Python Math

() —> ** —> *, /, //. % —> +, -

35
New cards

True or False: / always produces a float, even when the division is exact

True

36
New cards

True or False: Use / if you want a whole number

False

37
New cards

4 / 2

2.0

38
New cards

4 / / 2

2

39
New cards

Floats are ___________, not exact decimals

Approximations

40
New cards

Dividing by zero creates what type of error?

A ZeroDivisionError

41
New cards

What are Python’s comparison operators?

>, <, <=, >=, ==, !=

42
New cards

What data type results from a comparison?

bool

43
New cards

What are the two values of bool?

  • True

  • False


44
New cards

When an expression contains both calculations and comparisons, which happens first?

Calculations

45
New cards

== vs. =

== asks a question while = gives an instruction