0% found this document useful (0 votes)
3 views

Notes Python

The document discusses Python variables and data types, math functions in Python, and slicing strings. It covers integer, float, string, and boolean data types, and how to determine a variable's type. Math functions covered include round, floor, ceil, abs, pow, sqrt, min, and max. String slicing allows extracting substrings from a string using indexes and steps.

Uploaded by

Maria Regina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Notes Python

The document discusses Python variables and data types, math functions in Python, and slicing strings. It covers integer, float, string, and boolean data types, and how to determine a variable's type. Math functions covered include round, floor, ceil, abs, pow, sqrt, min, and max. String slicing allows extracting substrings from a string using indexes and steps.

Uploaded by

Maria Regina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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

2. Example - explanation: the number for stop in the code is exclusive :


name = "Reger Reg"
first name = name [0 : 6]
print(first name)
___
Reger

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

4. Example - the reversed code: will

You might also like