Python_Refresher_3
Python_Refresher_3
"""
This is a
multi-line
comment
"""
Variable / Box will store what kind of data. Is represented by data type.
int num;
num =5;
# Data types: int, float, str, bool, list, tuple, dict, set
# definition
def myfunc(){
// code
}
# calling a function
myfunc();
myCalculator( 10 , 6 );
}
# Create an empty list
my_list = [ ]
my_list = [1, 2, 3, 4, 5 ]
len(numbers)
Accessing Elements:
first_element = my_list[0]
last_element = my_list[-1]
Slicing
# Extracting a sublist
my_list.append(6)
Removing Element
# Remove the first occurrence of a value
my_list.remove(3)
List Operations:
my_list1 = [1, 2, 3, 4, 5]
my_list2 = [6,7]
# Concatenation
# Repetition
repeated_list = my_list * 3
List Methods:
length = len(my_list)
my_list.sort()
my_list.reverse()
index = my_list.index(4)
count = my_list.count(2)
my_list.clear()
## List to be continued