Python - Basics

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/83

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

84 Terms

1
New cards

Reserved Words

Essential vocabulary in Python that cannot be used as Variables

2
New cards

Same

Single and double quotes do the () thing in Python

3
New cards

>>>

“What do you want me to do next?”

4
New cards

Interpreter

Python is an () language

5
New cards

Interpreter Language

Program that analyzes and executes each line of code.

6
New cards

Machine Language

Programming language using binary or hexadecimal instructions that a computer can directly respond to.

7
New cards

Variable

Item that holds a value while a program is running.

8
New cards

Compiler

Program that converts instructions into a machine-code so that they can be read and executed by a computer.

9
New cards

Symbol for quote(s)

‘ or “

10
New cards

String

A sequence of characters enclosed (like a sentence) in single or double quotes

11
New cards

Script

A file that holds Python instructions.

12
New cards

quit()

there is o need to have () at the end of the Python program in the file as it knows to stop when reaching the end.

13
New cards

Sequential execution

Perform statements one after another in the order they are encountered in the script.

14
New cards

Conditional execution

Check for certain conditions and then execute or skip a sequence of statements.

15
New cards

Repeated execution

Perform some set of statements repeatedly, usually with some variation.

16
New cards

Reuse

Give a set of instructions a name so you can use them again whenever you need to.

17
New cards

Syntax errors

An error when you violate the grammar rules of the program, such as forgetting () or quotes

18
New cards

Logic errors

When the program has proper syntax BUT there is a mistake in the order of statements or how they are related. “take a drink from your water bottle, put it in your backpack, walk to the library, and then put the top back on the bottle.”

19
New cards

Semantic errors

Statements are semantically correct AND in the right order, however does not intend what you want it to do (accidentally giving wrong directions)

20
New cards

Debugging

The process of finding the cause of the error in your code.

21
New cards

Random walk programming

Making random changes in the program until it works. Takes a while and can be inefficient.

22
New cards

Main memory

Where in the computer is a variable such as “x” stored after the following Python line executes?

23
New cards

Strings, quotation

() will be enclosed in () marks

24
New cards

Str

Symbol for String

25
New cards

Int

Symbol for Integer

26
New cards

Float (Floating Point)

For the purposes of this coding language, numbers with decimal points like 32.5 (approximate values)

27
New cards

String

The values “17” and “3.2” are what type (Note the quotations, what does that tell you?)

28
New cards

Commas, Quotations

To print an integer don't use () or ()

29
New cards

Bool

Symbol for Boolean

30
New cards

Boolean

A data type with two possible values: True or false

31
New cards

Variable

A name that refers to a value.

32
New cards

Number

Variables CANNOT start with a ()

33
New cards

Lower-case, upper-case

You should start variables with () letters as opposed to () case

34
New cards

Space

You cannot have a () in the variable name.

35
New cards

Statement

a unit of code that the Python interpreter can execute.

36
New cards

Assignment

The process of giving value to a variable is called a(n)

37
New cards

Operators

Special symbols that represent computations like addition and multiplication.

38
New cards

Exponentiation

What does ** mean?

39
New cards

//

To get an integer answer in python as opposed to a floating point in division, what symbol do you use?

40
New cards

%

Modulus operator

41
New cards

Expression, Interpreter

A combination of values, variables, and operators. ONLY WORKS IN AN ()

42
New cards

Concentration, +

Joining the strings by linking them end to end. What is the symbol used?

43
New cards

Multiply

You can also () strings by using *

44
New cards

Addition assignment operator (+=)

adds two values and assigns the sum to a variable (left operand). Ex:
X = 5
print("Value Before Change: ", X)
X += 15
print("Value After Change: ", X)

45
New cards

int()

What function is used to convert string values to integers?

46
New cards

\n

What sequence is used to create a newline at the end of statements?

47
New cards

Parse Error

Most common error in Python. Tends to occur when missing parenthesis or other syntax. Make sure parenthesis are balanced so the code runs correctly.

48
New cards

Type Error, integer

A coding error where you combine two objects that are not compatible, such as adding an () and string together.

49
New cards

Store, x = int(x)

int(x) converts the string to an integer, but doesn’t () it anywhere. In this case you may need to use the assignment statement (), as it changes what x references the RETURNED integer value (allowing us to avoid a type error such as adding an integer + string together)

50
New cards

NameError

A common type of error that comes from using a variable before it has a value or simply caused by typos in the code. You can tell if the word only appears once in the code on the right side of the assignment statement.

51
New cards

Variables

You need to keep track of the restrictions needed for your (), and understand what your function is expecting. You can do this by writing comments in your code, or by naming your variables in a way that reminds you of their proper form.

52
New cards

Backwards

Work () from the error. This is because what caused the error usually happens in the code before it.

53
New cards

Automatically

Using commas () inserts spaces

54
New cards

Strings

True and False are not (). There are bool

55
New cards

X is NOT equal to Y

x != y

56
New cards

==

Boolean 56

57
New cards

and, or, not

The three logical operators include (), () and ()

58
New cards

Not

The () operator negates a boolean

59
New cards

Condition

The boolean expression after the if statement is called the ()

60
New cards

Alternative execution

A second form of an if statement where there are two possibilities and the condition determines which one gets executed. Also known as branches

61
New cards

Elseif

There is no limit on the number of () statements. If there is an else clause, it has to be at the end, but there doesn’t have to be one.

62
New cards

Chained Conditionals

a "chain" or a combination or multiple conditions

63
New cards

Nested Statements

Simply putting code inside of other code. For example placing an if statement inside of an already existing if statement. Best to avoid or it becomes too messy.

64
New cards

Try, Except

() and () feature in Python as an “insurance policy” on a sequence of statements.

65
New cards

catching an exception

Handling an exception with a try statement

66
New cards

Left, Right

When Python is processing a logical expression such as x >= 2 and (x/y) > 2, it evaluates the expression from () to ()

67
New cards

Short-circuit evaluation

When the evaluation of a logical expression stops because the overall value is already known (I.E. evaluates the whole statement to be false)

68
New cards

Guard

In the second expression, we say that y != 0 acts as a () to insure that we only execute (x/y) if y is non-zero. This evaluation is to prevent a run-time error where it divides the equation by 0.

69
New cards

Green, Red, True, True, 0

() = True Statement (evaluates the whole expression as true and computes

() = False Statement (evaluates whole expression as false so it stops after the initial statement due to short-circuit evaluation)

The third statement produces a run-time error because since the first statement (x) is (), it also assumes the second statement is (). However, since Y is = to (), it attempts to divide it by that value.

<p>() = True Statement (evaluates the whole expression as true and computes<br><br>() = False Statement (evaluates whole expression as false so it stops after the initial statement due to short-circuit evaluation)<br><br>The third statement produces a run-time error because since the first statement (x) is (), it also assumes the second statement is (). However, since Y is = to (), it attempts to divide it by that value. </p>
70
New cards

Caused

In general, error messages tell you where the problem was discovered, but that is often not where it was ().

71
New cards

ValueError

Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError. (A built in exception)

72
New cards

Function

named sequence of statements that performs a computation

73
New cards

Argument

a value or variable that we are passing into the function as input to the function. Inside the parenthesis of it.

74
New cards

Return

The result of the argument in a function

75
New cards

Built

The max and min functions that give us the highest/lowest values of each number is () into Python

76
New cards

Len (length)

tells us how many items are in its argument. Spaces ALSO count.

77
New cards

int(), float(), str(), NOT

Type conversion function examples. The int function does () round up

78
New cards

Math Module

provides most of the familiar mathematical functions.

79
New cards

Dot Notation

To access one of the functions, you have to specify the name of the module and the name of the function, separated by a dot. This is known as () () i.e. math.log10(ratio)

80
New cards

Random Module

provides functions that generate pseudorandom numbers

81
New cards

Choice

To choose an element from a sequence at random

82
New cards

Def

indicates that something is a function definition

83
New cards

Header, Body, Header, 4

The first line of the function definition is called the (), while the rest is called the (). The () must end with a : (colon). You should Indent () spaces after the header.

84
New cards

Error

If we move the function call above the definition we will get an ()