Demo Lecture Part 1 Flashcards

Writing our first program Writing Comments, Variables and data strutures, User inputs, Conditions, Loops

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
Q

class keyword

A

To define a class

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

continue

A

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
Q

def

A

for defining a function

28
Q

del

A

To delete an object

29
Q

elif

A

or else, if. (condition)

30
Q

else

A

if all of the above conditions are not true, do this

31
Q

except

A

Used with exceptions, what to do when an exception occurs

32
Q

finally

A

Used with exceptions, a block of code that will be executed no matter if there is an exception or not

33
Q

for

A

“applying to the following”

34
Q

from

A

To import specific parts of a module

35
Q

global

A

To declare a global variable

36
Q

if

A

in the case that (followed by a condition)

37
Q

import

A

To import a module

38
Q

in

A

To check if a value is present in a list, tuple, etc.

39
Q

is

A

To test if two variables are equal

40
Q

lambda

A

To create an anonymous function(one that does not have a name), takes any number of arguments but limited to only ONE expression

41
Q

nonlocal

A

To declare a non-local variable

42
Q

not keyword

A

A logical operator.The return value will be True if the statement(s) are not True , otherwise it will return False .

43
Q

or keyword

A

A logical operator.one or both of the epressions must be true for the statement to be true.

44
Q

pass keyword

A

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
Q

raise keyword

A

To raise an exception

46
Q

return keyword - what does it do?

A

To exit a function and return a value

47
Q

try keyword

A

To make a try…except statement

48
Q

while keyword

A

To create a while loop

49
Q

with keyword

A

used in exception handling to make the code more readable. It simplifies the management of common resources like file streams.

50
Q

yield keyword

A

To end a function, returns a generator

51
Q

how do you get the data type of a variable or other piece of data?

A

type(data)

52
Q

+ operator

A

adds two operands

53
Q

(-) operator

A

subtracts two operands

54
Q

(*) operator

A

multiplies two operands

55
Q

/ operator

A

division. divides first operand by the second. returns a float

56
Q

// operator

A

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
Q

% operator

A

modulus:

returns REMAINDER when first operand is divided by the second

58
Q

** operator

A

to the power of. first # raised to the power of second #

59
Q

idx

A

abbreviation for index

60
Q

can you define a functionw ithin a function? what’s it called?

A

yes
nested function

61
Q

how do you produce numbers corresponding to list elements?

A

enumerate function:

enumerate(iterable, start=int)

62
Q

what is a range? and what is the syntax?

A

a slice of a number line

(x=starting number, y=number AFTER ending number, z=increments)

63
Q

what is a factorial?

A

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
Q
A