Code is a set of directions to do one thing particular, given to a pc.
Variables are labels to containers of saved data
Python Objects have worth and kind.
Easy object sort consists of String, Integer, Float, Boolean and NoneType.
Use the kind(object) operate to know the kind of object.
# string
a = “abc”
#
print(sort(a))
# Integer
a = 1
#
print(sort(a))
# Float
a = 1.0
#
print(sort(a))
# Boolean (True or False)
a = True
#
print(sort(a))
# NoneType
a = None
#
print(sort(a))
Compound sorts are listing, tuple and dictionary.
# listing
a = [1, “pizza”]
#
print(sort(a))
# tuple
a = (1, ”pizza”)
#
print(sort(a))
# dictionary
a = { “a”: 1, “1”: [2]}
#
print(sort(a))
# Record
numbers = [“one”, “two”, “three”]
# one
print(numbers[0])
# three
print(numbers[-1])
numbers.append(“4”)
# 4
print(numbers[-1])
numbers[-1] = “5”
print(numbers) # [“one”, “two”, “three”, “five”]
# Tuple
numbers_2 = (“one”, “two”, “three”)
# one
print(numbers_2[0])
# three
print(numbers_2[-1])
# tuple is immutable. we couldn’t change it.
numbers_2 = (“one”, “two”, “three”, “5”)
print(numbers_2) # (“one”, “two”, “three”, “5”)
# dictionary
numbers_3 = {“one”:1, “two”:2, “three”:3}
# 1
print(numbers_3[“one”])
# 3
print(numbers_3[“three”])
numbers_3[“four”] = 4
# {“one”:1, “two”:2, “three”:3, “4”:4}
print(numbers_3)
# dict_keys( [ “one”, “two”, “three”, “four”] )
print(numbers_3.keys())
# dict_values( [ 1, 2, 3, 4] )
print(numbers_3.values())
# dict_items( [ (“one”, 1), (“two”, 2), (“three”, 3), (“four”,4) ] )
print(numbers_3.gadgets())
Booleans in Python:
1)not operator will adverse True to False and False to True.
not True returns False
not False returns True
2)and operator will return True provided that all of the values are True
True and False returns False
True and True returns True
3)or operator will return True if any of the values is True.
True or False returns True
False or False returns False
Comparability operators
1)== Operator returns True if each values are identical
3.0 == 3 returns True
“3” == 3 returns False
2)!= Operator returns True if each values are totally different
3.0 != 3 returns False
“3” != 3 returns True
3)> operator returns True if worth 1 is greater than worth 2
3 > 1 returns True
3 > 10 returns False
4)
3
3
5) >= operator returns True if worth 1 is larger than or equal to worth 2
3 >= 3 returns True
3 >= 2 returns False
6)
3
3
7) in operator returns True if value1 is in a listing/dictionary/string of values.
1 in [1,2,3,4] returns True
10 in “111” returns False
Conditional statements.
If A is True, then “A is True” shall be printed.
If A is False, then “A is False” shall be printed.
If A is neither True nor False, then “A is unknown” shall be printed.
if A==True :
print(“A is True”)
elif A == False:
print(“A is False”)
else:
print(“A is unknown”)