Demo Lecture Part 1 Flashcards

Writing our first program Writing Comments, Variables and data strutures, User inputs, Conditions, Loops (64 cards)

1
Q

break keyword

A

gives us the ability to exit out of loops whenever we want

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

how do you create an infinite loop?

A

while(True):

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

what is a boolean value?

A

True or False

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

what is an int data type?

A

integer: positive or negative whole number and zero

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

what is a float data type?

A

a decimal

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

what is a string data type?

A

a sequence of characters “abc123”

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

what is a list data type?

A

an ordered sequence of values of other data types [1, 2, 3]

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

what is a dictionary data type?

A

an unordered collection of key: value pairs eg {“firstname”: “Colt”, “lastname”: “Steele”}

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

string formatting expression using .format and variables

A

1 define variables
2 print string
3 print string, close with quotes, then .format in round brackets listing variables in order

first_name = “Prerna”
country = “India”
print(“My name is {}. I stay in {}.”.format(first_name,country))

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

string formatting with f strings

A

1 define variables
2 f’string’
3 variables go in curly brackets

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

can you reassign the same variable to different values?

A

yes. python will use the last one you wrote

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

what are the python naming restrictions? are variables case-sensitive?

A

must start with an underscore or letter. rest of the string can be letters, underscores, or numbers. cannot begin a variable with a number. variables ARE case-sensitive

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

how do you write a multi-line comment?

A

three double quotationcan s

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

how can we capture user input? what data type does it expect?

A

input(“text for input request).

built-in function that will store user input into a variable. expects a string, so any other type of input must be typecast to the correct data type

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

difference between spacing:
print(“Prerna”+”Gupta”)
print(“Prerna”,”Gupta”)

A

+ > no space
, > space by default

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

how can you get help with a keyword?

A

print(help(“keyword”))

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

False

A

opposite of true, truth value 0

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

None

A

None is an instance of the NoneType object type. While new NoneType objects cannot be generated, None can be assigned to any variable.

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

True

A

opposite of false, truth value 1

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

and

A

A logical operator.both things on either side of and must be true for the entire statement to be true

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

as

A

creates an alias

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

assert

A

for debugging

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

async

A

async” defines a coroutine

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

await

A

await” suspends or yields execution to another coroutine from within a coroutine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
class keyword
To define a class
26
continue
loop control statement. the code inside the loop following the continue statement will be skipped for the current iteration and the next iteration of the loop will begin.
27
def
for defining a function
28
del
To delete an object
29
elif
or else, if. (condition)
30
else
if all of the above conditions are not true, do this
31
except
Used with exceptions, what to do when an exception occurs
32
finally
Used with exceptions, a block of code that will be executed no matter if there is an exception or not
33
for
"applying to the following"
34
from
To import specific parts of a module
35
global
To declare a global variable
36
if
in the case that (followed by a condition)
37
import
To import a module
38
in
To check if a value is present in a list, tuple, etc.
39
is
To test if two variables are equal
40
lambda
To create an anonymous function(one that does not have a name), takes any number of arguments but limited to only ONE expression
41
nonlocal
To declare a non-local variable
42
not keyword
A logical operator.The return value will be True if the statement(s) are not True , otherwise it will return False .
43
or keyword
A logical operator.one or both of the epressions must be true for the statement to be true.
44
pass keyword
When the user does not know what code to write, So user simply places a pass at that line. Sometimes, the pass is used when the user doesn’t want any code to execute. So users can simply place a pass where empty code is not allowed, like in loops, function definitions, class definitions, or in if statements.
45
raise keyword
To raise an exception
46
return keyword - what does it do?
To exit a function and return a value
47
try keyword
To make a try...except statement
48
while keyword
To create a while loop
49
with keyword
used in exception handling to make the code more readable. It simplifies the management of common resources like file streams.
50
yield keyword
To end a function, returns a generator
51
how do you get the data type of a variable or other piece of data?
type(data)
52
+ operator
adds two operands
53
(-) operator
subtracts two operands
54
(*) operator
multiplies two operands
55
/ operator
division. divides first operand by the second. returns a float
56
// operator
floor division: divides first operand by the second, returns greatest integer less than or equal to dividend (number being divided) eg 10/3=3 because 3*3=9, which is the closest whole number to 10. essentially gives the greatest whole number of times the divisor can go into the dividend, gives no remainder.
57
% operator
modulus: returns REMAINDER when first operand is divided by the second
58
** operator
to the power of. first # raised to the power of second #
59
idx
abbreviation for index
60
can you define a functionw ithin a function? what's it called?
yes nested function
61
how do you produce numbers corresponding to list elements?
enumerate function: enumerate(iterable, start=int)
62
what is a range? and what is the syntax?
a slice of a number line (x=starting number, y=number AFTER ending number, z=increments)
63
what is a factorial?
the product of all positive integers less than or equal to a given positive integer and denoted by that integer and an exclamation point. Thus, factorial seven is written 7!, meaning 1 × 2 × 3 × 4 × 5 × 6 × 7.
64