Module 2 Flashcards

1
Q

variable

A

a storage location with a name. Each variable has a name and holds a value

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

Why is a variable similar to/compared to a parking space?

A

Parking space has an identifier and contents like a variable in a computer program

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

assignment statement

A

stores a value in a variable, aka you use it to place a value into a variable

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

example of an assignment statement

A

cansPerPack = 6

The left-hand side of an assignment statement consists of a variable. The right-hand side an expression that has a value. That value is stored in the variable.

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

When is a variable created

A

the first time it is assigned a value

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

What happens if you assign a value to an already existing variable?

A

It replaces the previously stored value

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

True or False: The assignment operator = does denote mathematical equality

A

FALSE: It does NOT denote mathematical equality. Assignment is an instruction to do something – namely, place a value into a variable, not the equal symbol in algebra to denote equality.

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

data type

A
  1. determines how the data is represented in the computer and what operations can be performed on that data.
  2. Specifies how the value is stored in the computer and what operations can be performed on the value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

primitive data type

A

a data type provided by the language itself

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

What data types does Python support?

A

numbers, text, strings, files, containers, and many others.

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

Integer

A

In python it is called int

Whole numbers without a fractional part. No fractions or decimals.

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

floating-point numbers

A

called float in Python

unlike integers (whole numbers), they are fractional numbers (such as 0.555)

OR

numbers with exponential notation

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

float vs int in Python

A

float is a floating-point number/value (fractional numbers or numbers with exponential notation)

int is an integer value/number (whole numbers)

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

Number literal

A

a fixed value in a program this is explicitly written as a number, such as -2 or 6.02214115E23

can be an integer or floating point number

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

Why should you always store values of the same type once a variable is initialized?

A

It helps avoid error in your code.

Example:

taxRate = 5.0

Although the number is a whole number, it is stored as a floating point number because you can get a fractional number later in your code. This avoids error by all number being unified by using floating point numbers and not a mix of integers and floating point numbers.

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

Naming something in Python rules:

A
  1. Names must start with a letter or an underscore, and remaining characters must be letters, numbers, or underscores.
  2. You cannot use symbols such as ? or %. Spaces are not permitted. You can use uppercase letters to denote word boundaries, as in cansPerPack.
  3. Names are case sensitive

4.You cannot used reserved words (words reserved for their special Python meanings), such as if or class.

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

Why should you start names with a lower case?

A

Names that are all uppercase indicate constants, and names that start with an uppercase letter are commonly used for user-defined data types.

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

Constant/constant variable

A

a value that should not/cannot by changed by a program. In Python, constants customarily have names consisting of all uppercase letters.

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

Comments

A

an explanation to help the human reader understand a section of a program; ignored by the interpreter.

uses a hashtag(#)

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

Why are comments a good practice?

A

It helps programmers who read your code understant your intent.

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

magic number

A

a numeric constant that appears in your code without explanation

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

Why should you avoid magic numbers

A

In rare circumstances, a constant may need to change. If so a magic number would need to be manually changed. It also provides more descriptive factors.

23
Q

What arithmetic operations can Python run?

A

the four basic ones as a calculator: addition, subtraction, multiplication, and division

24
Q

** in python

A

to show when something is to the power of something

25
Q

// in python

A

division, but it discards the remainder (fractional) to keep it an integer

26
Q

floor division

A

Taking the quotient of two integers and discarding the remainder. In Python the // symbol denotes floor division.

Ex: 11//4 is 2, not 2.75

27
Q

abs in Python

A

returns the literal/absolute value

example

abs (-10) will return the value as 10

28
Q

round in Python

A

when presented with one argument, it will round to the nearest integer. When presented with 2 arguments, it will use the second argument to specify the desired number of fractional digits

Example:

1 argument: round (2.555) -> 3
2 arguments:
round (2.555, 2) -> 2.56 OR
round (2.555[, 2]) -> 2.56

29
Q

min in Python

A

sets variables to the lowest number in the functions arguments. It takes an arbitrary number of arguments.

example: cheapest = min (5, 20, 13, 10)
cheapest would be set to 5

30
Q

max in Python

A

sets variables to the largest number in the functions arguments. It takes an arbitrary number of arguments.

example: cheapest = max (5, 20, 13, 10)
cheapest would be set to 20

31
Q

Return Value

A

The value returned by a method or function through a return statement. Can be used anywhere a literal value can be used.

32
Q

Literal

A

a notation for a fixed value in a program, such as 2, 3.24, 6.00034E23, “Harry”, or “H”

33
Q

library

A

a collection of code that has been written and translated by someone else, ready for you to use in your program

34
Q

standard library

A

a library that is considered part of the language and must be included with any Python system

35
Q

from in Python

A

used to call a module from the program’s library

36
Q

import in Python

A

used to import a function from a library in your program

37
Q

built-in functions

A

functions that are defined as part of the language itself and can be used directly in your programs. Can be used without importing any module

38
Q

True or False: You can combine arithmetic and assignments in Python?

A

Yes, typically for short cuts

example:

total*=1 —-> total = total * 2

39
Q

strings

A

a sequence of characters

ex: “Hello” is a sequence of five characters

40
Q

string literal

A

denotes as a particular string (such as “hello”)

specified by enclosing a sequence of characters within a matching pair of either single or double quotes

41
Q

length in Python

A

the number of string characters in a string

ex: “hello” has a length of 5

42
Q

len in Python?

A

len function is the length, and is used to compute the length of a string

43
Q

empty string

A

a string of 0 is called an empty string. Usually written as “ “ or ‘ ‘

44
Q

concatenate/concatenation

A

placing one string after another to form a new string

ex:

firstName = Freya
lastName = Rios
name = firstName + lastName —> Freya Rios

45
Q

How do you concatenate strings

A

with the + operator

46
Q

How can you repeat strings

A

using the * operator, the number of repetitions must be an integer

47
Q

str in Python

A

converts an integer to floating-point value to a string

ex:
str(123) —> “123”

48
Q

Unicode

A

A standard code that assigns code values consisting of two bytes to characters used in scripts around the world. Python stores all characters as their Unicode values.

49
Q

What are strings sequences of?

A

Sequences of unicode characters.

50
Q

How are string positions counted

A

string positions are counted starting with 0.

51
Q

index

A

Position of a character within a string

52
Q

How do you access an individual character to find the position of

A

with brackets

example:

name= “Harry”

first = name [0]
last = name [4]

53
Q

len function in Python

A

can be used to determine the position of the last index/ the last character in a string

54
Q
A