Hello! My name is Rick and I am in search for gig as a developer :)
This past December I finished up a year long study with a full-stack school in NYC called Codeimmersives. We explored HTML, CSS, JavaScript, and how to build applications using the MERN stack. I learned about class-based components, passing props around (prop-drilling) and utilizing the component lifecycle(componentWillMount, componentDidMount, etc). After learning class based components, we moved on to functional based components using hooks, custom hooks, and different ways to manage state, such as the useContext and Redux APIs. (This is just a brief overview of the technologies I studied over the past year). Currently I am enrolled at devCodeCamp learning the basics of Python. I am documenting my journey by sharing these blog posts. Please help me out by dropping a comment below on what you think!
Loops in python
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
The above loop works the same for strings as it does lists.
The range() function
# starts at 0 increments by 1 (default) till 6 (not including 6)
for x in range(6):
print(x)
# starts at 2 and runs till 6 (not including 6)
for x in range(2, 6):
print(x)
# starts at 2, runs till 30 (not including 30) increments by 3
for x in range(2, 30, 3):
print(x)
Functions in python
def add_two_numbers(first_number, second_number):
result_sum = first_number + second_number
return result_sum
Void function - is a function that does not send anything back (no return)
Pure function - a function whose output value follows solely from its input values, without any observable side effects
modules
files with the “.py” extension containing Python code that can be imported inside another Python Program.
In simple terms, we can consider a module to be the same as a code library or a file that contains a set of functions that you want to include in your application.
Function exercise
I know these may seem basic but this is just meant to be an introduction to functions in python
def display_name(name):
print(name)
display_name('Mike')
display_name('Ian')
display_name('Nevin')
def add_one_to_number(number):
number_one = 1
add_one = number + number_one
return add_one
result = add_one_to_number(30)
def add_two_nums(num1, num2):
result = num1 + num2
return result
add_two = add_two_nums(5,11)
print(add_two)
def concat_two_strings(str1, str2):
result = str1 + ' ' + str2
return result
concat_two = concat_two_strings('Rick', 'Rieger')
print(concat_two)
def print_each_char(str):
for char in str:
print(char)
print_each_char('devCodeCamp')
def is_less_than_three_chars(str):
if len(str) >= 3:
print(str)
else:
print('we need a larger string to print!')
string_to_be_evaluated = input('Provide a string to print to console ')
if string_to_be_evaluated:
is_less_than_three_chars(string_to_be_evaluated)
Lists
A ordered collection, data structure that can be manipulated
my_list = [1,3,4,3,6,4]
my_list[3] = 44
adds to end of list
append() method
my_list.append(33)
# [1,3,4,3,6,4,33]
##pop() method
removes from last index or the index passed
my_list.pop()
# [1,3,4,3,6,4]
my_list.pop(2)
# [1,3,3,6,4]
remove() method
removes item passed in
my_list.remove(6)
# [1,3,3,4]
len() method
gets length of string or list
num = len(my_list)
loop over list
for num in my_list:
print(num)
Ex 1 with lists
def my_func(list_of_strings):
single_item = list_of_strings[0]
print(single_item)
return single_item
print('##### Exercise1 #####')
result1 = my_func(['sometimes', 'I', 'like', 'to', 'play', 'music'])
print(result1)
def my_func2(colors):
list_to_append = ['blue', 'red', 'white', 'green', 'yellow']
for color in list_to_append:
colors.append(color)
users_color = input('Please provide a color:')
for color in colors:
if users_color.lower() == color.lower():
print('You found my chosen color!')
print('##### Exercise2 #####')
print(my_func2(['black', 'orange', 'brown', 'pink', 'gray']))
def add_all_nums_in_list(numbers):
total = 0
for num in numbers:
total += num
if (total % 2) == 0:
print('Even')
else: print('Odd')
print('##### Exercise3 #####')
print(add_all_nums_in_list([2, 6, 1, 3, 1]))
def greater_than_this_num(list_of_nums, num_passed):
for num in list_of_nums:
if num > num_passed:
print(num)
print('##### Exercise4 #####')
result4 = greater_than_this_num([2, 6, 11, 13, 1], 10)
print(result4)
Ex 2 with lists
def my_func(list_of_strings):
single_item = list_of_strings[0]
print(single_item)
return single_item
print('##### Exercise1 #####')
result1 = my_func(['sometimes', 'I', 'like', 'to', 'play', 'music'])
print(result1)
def my_func2(colors):
list_to_append = ['blue', 'red', 'white', 'green', 'yellow']
for color in list_to_append:
colors.append(color)
users_color = input('Please provide a color:')
for color in colors:
if users_color.lower() == color.lower():
print('You found my chosen color!')
print('##### Exercise2 #####')
print(my_func2(['black', 'orange', 'brown', 'pink', 'gray']))
def add_all_nums_in_list(numbers):
total = 0
for num in numbers:
total += num
if (total % 2) == 0:
print('Even')
else: print('Odd')
print('##### Exercise3 #####')
print(add_all_nums_in_list([2, 6, 1, 3, 1]))
def greater_than_this_num(list_of_nums, num_passed):
for num in list_of_nums:
if num > num_passed:
print(num)
print('##### Exercise4 #####')
result4 = greater_than_this_num([2, 6, 11, 13, 1], 10)
print(result4)