VOCAB!
x = 5
y = "Ananya"
print(x)
print(y)
x = 5
print(type(x))
thislist = ["apple", "banana", "cherry"]
print(thislist)
myfamily = {
"child1" : {
"name" : "Emil",
"year" : 2004
},
"child2" : {
"name" : "Tobias",
"year" : 2007
},
"child3" : {
"name" : "Linus",
"year" : 2011
}
}
Booleans Expressions and Selection
A boolean expression (or logical expression) evaluates to one of two states true or false. Python provides the boolean type that can be either set to False or True. Many functions and operations returns boolean objects. The not keyword can also be used to inverse a boolean type.
Charcters
Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.
a = """HELLO HELLO
HELLOHELLO
HELLOHELLOHELLO
"""
print(a)
a = "Hello"
print(a)
print(10 > 9)
print(10 == 9)
print(10 < 9)
print(10 + 5)
thistuple = ("apple", "banana", "cherry")
print(thistuple)
Python Conditions and If statements
Python supports the usual logical conditions from mathematics:
- Equals: a == b
- Not Equals: a != b
- Less than: a < b
- Less than or equal to: a <= b
- Greater than: a > b
- Greater than or equal to: a >= b
- These conditions can be used in several ways, most commonly in "if statements" and loops.
An "if statement" is written by using the if keyword.
a = 33
b = 200
if b > a:
print("b is greater than a/")
i = 1
while i < 6:
print(i)
i += 1
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
def my_function():
print("Hello from a function")