Demo Lecture Part 1 Flashcards
Writing our first program Writing Comments, Variables and data strutures, User inputs, Conditions, Loops
break keyword
gives us the ability to exit out of loops whenever we want
how do you create an infinite loop?
while(True):
what is a boolean value?
True or False
what is an int data type?
integer: positive or negative whole number and zero
what is a float data type?
a decimal
what is a string data type?
a sequence of characters “abc123”
what is a list data type?
an ordered sequence of values of other data types [1, 2, 3]
what is a dictionary data type?
an unordered collection of key: value pairs eg {“firstname”: “Colt”, “lastname”: “Steele”}
string formatting expression using .format and variables
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))
string formatting with f strings
1 define variables
2 f’string’
3 variables go in curly brackets
can you reassign the same variable to different values?
yes. python will use the last one you wrote
what are the python naming restrictions? are variables case-sensitive?
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 do you write a multi-line comment?
three double quotationcan s
how can we capture user input? what data type does it expect?
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
difference between spacing:
print(“Prerna”+”Gupta”)
print(“Prerna”,”Gupta”)
+ > no space
, > space by default
how can you get help with a keyword?
print(help(“keyword”))
False
opposite of true, truth value 0
None
None is an instance of the NoneType object type. While new NoneType objects cannot be generated, None can be assigned to any variable.
True
opposite of false, truth value 1
and
A logical operator.both things on either side of and must be true for the entire statement to be true
as
creates an alias
assert
for debugging
async
async” defines a coroutine
await
await” suspends or yields execution to another coroutine from within a coroutine.
class keyword
To define a class