Unit 3 Vocabulary
Unit 3 Vocabulary and Examples
age = 15
name = "Soham"
- Managing Complexity with Variables
- Lists - any information displayed or organized in a logical or linear formation
- 2D Lists - list of lists
- Dictionaries - an abstract data type that defines an unordered collection of data as a set of key-value pairs
- Class - a template definition of the method s and variable s in a particular kind of object
animals = ["dogs","cat"]
- Algorithms
- Sequence - the first programming construct
- Selection - a programming construct where a section of code is run only if a condition is met
- Iteration - a process where the design of a product or application is improved by repeated review and testing
def isPalindrome(s):
return s == s[::-1]
# Driver code
s = "malayalam"
ans = isPalindrome(s)
if ans:
print("Yes")
else:
print("No")
- Expressions
- Comparison Operators - operators that compare values and return true or false
- Truth Tables - A truth table is a way of summarising and checking the logic of a circuit. The table shows all possible combinations of inputs and, for each combination, the output that the circuit will produce.
print(5>2)
- Characters - a display unit of information equivalent to one alphabetic letter or symbo (char)
string = "Hello, world!"
characters = list(string)
print(characters)
- Strings - A string is generally considered a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding.
info = 15
print(str(info))
- Length - length of a string
info = "fiwhasnoguhebiudsnoidkj"
print(len(info))
- Concatenation - combining 2 or more strings
string1 = "Hello"
string2 = "world"
concatenated_string = string1 + " " + string2
print(concatenated_string)
- Upper - converts the string to uppercase
info = "OIJHUHYBNJJIHUfoeiajnjieofoJIPOUBYUV"
print(info.upper())
- Lower - converts the string to lowercase
info = "OIJHUHYBNJJIHUfoeiajnjieofoJIPOUBYUV"
print(info.lower())
- Traversing Strings - accessing all the elements of the string one after the other by using the subscript
string = "Hello, world!"
for character in string:
print(character)
- Python If - a statement with an if condition
if 6<9:
print("no")
- Elif - when the if condition is not met, it comes here. Used when you want to add multiple other conditions
elif 5>4:
print("maybe")
- Else conditionals - when the if condition is not met, it comes here.
else:
print("yes")
- Nested Selection Statements - selection statements that are nested within themselves
x = 10
y = 20
if x > 5:
if y > 15:
print("x is greater than 5 and y is greater than 15")
else:
print("x is greater than 5 but y is not greater than 15")
else:
print("x is not greater than 5")
- Python For - a condition that repeats multiple times
for i in range(0,6):
print(i,"cookies")
- While loops with Range - while loop that uses the range() function
i = 5
while i in range(0,6):
print(i,"cookies")
i = i - 1
- with List - Lists are used to store multiple items in a single variable.
numbers = [1, 2, 3, 4, 5]
for index, number in enumerate(numbers):
print(f"Number at index {index}: {number}")
- Combining loops with conditionals to Break, Continue - For certain conditions, the loop will terminate exectution
for i in range(10):
if i % 2 == 0:
continue
print(i)
# Output: 1 3 5 7 9
- Procedural Abstraction - when we write code sections (called "procedures" or in Java, "static methods") which are generalised by having variable parameters.
def calculate_tax(price, tax_rate):
tax = price * tax_rate
total = price + tax
return total
print(calculate_tax(100, 0.1)) # Output: 110.0
- Python Def procedures - A procedure allows us to group a block of code under a name, known as a procedure name
def addition(x):
x = x + 5
return x
addition(5)
- Parameters - values that are passed through a function
def greet(name):
print(f"Hello, {name}!")
greet("John") # Output: "Hello, John!"
- Return Values - a value that a function returns to the calling script or function when it completes its task
def add(x, y):
result = x + y
return result
print(add(10, 20)) # Output: 30