Unit 3 Vocab
Characters: Letters that make up words.
Letters = ["a, b, c, d, e, f"]
print(Letters)
Strings: Sequence of characters that represent text.
strings = ["apple, banana, carrot"]
print(strings)
Length: The amount of characters in a string.
string = "hellobye"
x = string[0:8]
y = string[0:5]
z = string[5:8]
print(x)
print(len(string))
print(y)
print(z)
Concatenation: combination of strings to make sentences.
string1 = ("Hello how are you?")
string2 = ("Im good!")
print(string1, string2)
Traversing Strings: Iterate over the characters in teh string.
greeting = "Hello, how are you?"
for o in greeting:
print(o)
Python if: An if statement is used when you want something to happen IF another thing has occurred.
x = 1
if x == 1:
print("x is 1")
Elif: It stands for else if, this is used when the first statement is false but you want to check for another condition.
price = 100
if price > 100:
print("price is greater than 100")
elif price == 100:
print("price is 100")
elif price < 100:
print("price is less than 100")
Else Conditional: This is used when the first statement is false so you want to run another statement.
hour = 19
if (hour < 18):
greeting = ("Good day")
else:
greeting = ("Good evening")
print (greeting)
Nested selection statements: whenever selection statements are inside another selection statement.
hour = 19
if hour > 15:
if hour == 15:
print("it is 15 hours")
elif hour == 16:
print("it is 16 hours")
elif hour == 17:
print("it is 17 hours")
elif hour == 18:
print("it is 18 hours")
elif hour == 19:
print("it is 19 hours")
While loops with range: While loop is code that keeps running until a certain condition is met, the range would cause only the things in that range to print.
for num in range(1, 11):
print(num)
With lists combining loops with conditionals to break: first create a list, then use a loop so it stops when it reaches a certain number in the list.
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for number in numbers:
if number == 7:
break
print(number)
Continue procedural abstraction: Variables are first defined, then later they are used again to solve the problem.
def multiply(x, y):
return x * y
x = 3
y = 6
print(multiply(x, y))
python def procedures: allows you to define a procedure so you can use it more efficiently later on.
def multiply(x, y):
return x * y
Parameters: Its a variable/placeholder for the values of a function.
def add(x, y):
return x + y # in this case the parameter is x and y
Return values: the value that function returns to when it wants to recall a variable.
def add(x, y):
return x + y
x = 3
y = 6
print(multiply(x, y)) # recalls a variable previously defined