Notes Python
Notes Python
Variables
Data types (so far)
-Interger (a data type for whole numbers), no "" allowed
-Float (a data type for decimal numbers), no "" allowed
-String (a data type for words)
-boolean (a data type that can only contain true or false) -> usually for if statements, no
quotes allowed
1. by
print(type(variable))
you can know the type of the variable
2. if variable type is not str we can do
print("value" + str(value2))
3. Multiple assignments
can a assign multiple variables in one code line
ex: Moline = Boline = Noline = 16
4.
Multiplications in string & intergers
string : *3 -> will result in ex:
Variable = Value
print(Variable*3)
result: value value value
intergers: *3 -> will result in ex:
Variable = 3
print(Variable*3)
result: 9
5. type casting, changing data types of variables
ex:
x=y
print("y is " +str(x))
Math functions
1.Round -> rounds a decimal number, will only round up a decimal if the tenths is 6 or more
2.Floor -> rounds a decimal number down
3.Ceil -> rounds a decimal number up
4.Abs -> makes a negative number positive
5.Pow -> to the power of ..
6.Sqrt -> square roots a number
7.Min -> finds the variable with the least value amongst variablkes
8.Max -> opposite of min
Slicing strings
[start : stop : step]
For slicing a value from a string, creating a substring
1. Example - Note: Slicing strings always starts from 0 & empty spaces counts :
name = "Reger Reg"
first name = name [0]
print(first name)
___
R
3. Example - the step code: will count only the Xth letter from the value:
name = "Reger Reg"
goofy_name = [0 : 10 : 2]
print(goofy_name)
__
RgrRg