Академический Документы
Профессиональный Документы
Культура Документы
Int
Float: Float can also be scientific numbers with an "e" to indicate the
power of 10.
complex: x = 3+5j , y = 5j
CASTING:
y = int(2.8) # y will be 2
STRING:
a = "Hello, World!"
print(a[1]) # returns e
print(len(a)) # returns 13
a = 200
b = 33
if b > a: m,
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
if a > b or a > c:
print("At least one of the conditions is True")
ARRAY: Arrays are used to store multiple values in one single variable
thislist = ["Ford", "Volvo", "BMW"]
x = thislist [0] # returns Ford
thislist [0] = "Toyota" # returns ['Toyota', 'Volvo', 'BMW']
thislist.append("Honda") # returns ['Ford', 'Volvo', 'BMW', 'Honda']
thislist.pop(1) # returns ['Ford', 'BMW']
thislist.remove("Volvo") # returns ['Ford', 'BMW']
thislist.insert(1, "Toyota") # returns ['Ford', 'Toyota','BMW']
Tuple:
A tuple is a collection which is ordered and unchangeable (we can’t add or
delete value after once it’s initialize). In Python tuples are written with round
brackets.
example:
thistuple[1] = "blackcurrant"
# The values will remain the same:
print(thistuple) # returns ('apple', 'banana', 'cherry')
SETS:
A set is a collection which is unordered and unindexed. In Python sets are
written with curly brackets. You cannot access items in a set by referring to an
index, since sets are unordered the items has no index.
# returns TRUE
LOOP:
while loops : With the while loop we can execute a set of statements as
long as a condition is true.
for loops : A for loop is used for iterating over a sequence (that is either
a list, a tuple, a dictionary, a set, or a string).
i = 1
while i < 6:
print(i)
if i == 3:
break # it could be continue or it could neither any of these 2
i += 1