Python Basics Flashcards

1
Q

What is code that returns a value when evaluated ?

A

Expressions. For example, the code wage * hours * weeks is an expression that computes a number.

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

What is a variable ?

A

Variables are named references to values stored by the interpreter. Example: Wages, Salaries, Hours. These can hold specific values.

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

What is an assignment ? Describe the syntax used.

A

An assignment is how you create new variables in python. A new variable is created using the = symbol. With the varialbe name on the left and the value on the right. Example future_car = 720s.

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

How to display variables or expression values in python ?

A

print()

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

What is the comment syntax in python ?

A

#

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

What is the syntax to keep subsequent print statements on the same line ? How to keep this output on same line:
print(‘Hello world.’)
print(‘You’re gay.’)

A

end=’ ‘
print(‘Hello world.’, end=’ ‘)
print(‘You’re gay.’)

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

How to output a variable name ?

A

print(variable_name)

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

What is the syntax for a newline character ?
How would you print the number 2 on a newline given:
print(1, 2)

A

\n.
print(‘1\n2’)

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

How to assign variable favorite_car, to input take from the user ?

A

favorite_car = input()

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

How to convert strings to integers ?
Convert my_int = ‘123’ to an integer.

A

int()
my_int = int(‘123’)

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

How to assign variable_name to an integer input by the user with an included prompt.

A

variable_name = int(input(‘: ‘, ))

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

What are three things that every python object possesses ?

A

Type, value, identity

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

What is an objects mutability and what determines it ?

A

Mutability means whether or not the object’s value can be changed. This is determined by type.

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

How to print an object’s type ?

A

print(type(‘ABC’))

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

What is an object’s identity ?

A

A unique identifier that describes the object. It usually references the object’s memory address where the object is stored.

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

What are the data types that can be created using python ?

A

String, integer, float,

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

What is a combination of items, like variables, literals, operators, and parentheses, that evaluates to a value, like 2 * (x + 1)

A

Expression

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

A symbol that performs built in calculations ?
Give 5 examples.

A

Operator
+ - / * **

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

What is a literal ?

A

A specific value in code like 2.

20
Q

Precedence rule order

A

(), **, unary-, */%, +-, left-to-right

21
Q

What is a script ?

A

A file containing Python code that is passed as input to the interpreter.

22
Q

What is dot notation ?

A

Used to reference an object in an imported module.

23
Q

What is the purpose of the import statement ?

A

To execute the contents of a file containing Python code and make available the definitions from that file.

24
Q

What is a module ?

A

A file containing Python code that is imported by a script, module, or interactive interpreter.

25
Q

What is the usage of the special name : __name__ ?

A

It is used to determine if the file was executed as a script by the programmer or imported by another module. If the value of __name__ is the string ‘__main__’, then the file was executed as a script.

26
Q

What is a function ?

A

A function is a list of statements that can be executed simply by referring to the function’s name, like the ones found in the math module.

27
Q

What is a function call ?

A

The process of invoking a function.

28
Q

What is the item passed to a function ?

A

Argument. A function can have several arguments.

29
Q

Which method returns a random integer between min and max ?

A

randint(min, max)

30
Q

Which method returns a random integer between min and max -1 ?

A

randrange(min, max)

31
Q

The numbers generated by the random module are known as __ ? The module has an equation to compute the next “random” number from the previous one, (invisibly) keeping track of the previous one.

A

Pseudo-random

32
Q

For the first call to any random method, no previous random number exists, so the method uses a built-in integer based on the current time, called a __ ?

A

Seed

33
Q

Specifying a seed() before using a random method will yield the same sequence of integers ?

A

True

34
Q

Program

A

consists of instructions executing one at a time. Instruction types include input, process, and output.

35
Q

Input

A

Instruction type. A program receives data from a file, keyboard, touchscreen, network, etc

36
Q

Process

A

Instruction type. A program performs computations on that data, such as adding two values like x + y.

37
Q

Output

A

Instruction type. A program puts that data somewhere, such as a file, screen, or network.

38
Q

Statement

A

a program instruction. A program mostly consists of a series of statements, and each statement usually appears on its own line.

39
Q

Syntax error

A

The program contains invalid code that cannot be understood

40
Q

Indentation error

A

The lines of the program are not properly indented.

41
Q

Value error

A

An invalid value is used, which can occur if giving letters to int().

42
Q

Name error

A

The program tries to use a variable that does not exist.

43
Q

Type error

A

An operation uses incorrect types, which can occur if adding an integer to a string.

44
Q

Logic error (bug)

A

Code that has correct syntax, but has a different meaning than intended. So the interpreter will not generate an error message, but the program’s output is not what the programmer expects.

45
Q

Arbitrary

A

based on random choice or personal whim, rather than any reason or system.

46
Q

Cache

A

Because speed is so important, a processor may contain a small amount of RAM on its own chip, called cache memory, accessible in one clock tick rather than several, for maintaining a copy of the most-used instructions/data.

47
Q

transistors

A

engineers created smaller switches called transistors, which in 1958 were integrated onto a single chip called an integrated circuit or IC. Oo