Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vekaev committed Jan 24, 2022
0 parents commit b0ca356
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 0-intro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
res1 = print('Hi')
res2 = int('2')
res3 = sum([1, 2, 3])
res4 = 'hi'.upper()

print('res1', res1, type(res1))
print('res2', res2, type(res2))
print('res3', res3, type(res3))
print('res4', res4, type(res4))
51 changes: 51 additions & 0 deletions 1-def.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# from datetime import datetime


def print_hello():
print('Hello')


# print


############################################################################


# def get_current_time():
# return datetime.now().strftime('%H:%M')

# get_current_time()


############################################################################


# res1 = print_hello()
# res2 = get_current_time()

# print('res1', res1, type(res1))
# print('res2', res2, type(res2))


############################################################################


# def int_input():
# while(True):
# res = input('Enter a number: ')
# if res.isdigit():
# return int(res)
# else:
# print('It\'s not a number')


# res1 = int_input()
# print(res1)


############################################################################

# test_func()

# def test_func():
# pass
39 changes: 39 additions & 0 deletions 2-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def greet(name):
print(f'Hello, {name}. How are you?')


greet('Bob')


################################################################


# def bread_factory(num):
# return '🍞' * num


# for i in range(1, 10):
# print(bread_factory(i))


################################################################


# def func1(f_name, l_name):
# print(f'Hello, {f_name} {l_name}')

# func1('Bob', 'Marley')
# func1('Bob')
# func1('Bob', 'Marley', 'Marley')


################################################################


# def func2(country="Norway"):
# print("I am from " + country)


# func2("Sweden")
# func2()
# func2("Brazil")
12 changes: 12 additions & 0 deletions 3-keyw-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def func1(a, b, c):
print(a, b, c)
print(a + b + c)


func1(a=1, b=2, c=3)
func1(c=3, b=2, a=1)

# func1(1, b=2, c=3)
# func1(a=1, 2, 3)

# func1(c=1)
42 changes: 42 additions & 0 deletions 4-fixed-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
def func1(*langs):
print(langs, type(langs))
print("The oldest language is " + langs[1])


def func2(*langs):
for i in range(len(langs)):
print("The best language is " + langs[i])


func1("C++", "JS", "Python")
func2("C++", "JS", "Python")


################################################################


# langs = ["C++", "JS", "Python"]

# def func3(langs):
# for i in range(len(langs)):
# print("The best language is " + langs[i])

# func3(langs)

################################################################


# func1(langs)
# func2(langs)


# name = ['Bob', 'Marley']


# def func4(f_name, l_name):
# print(f'Hello, {f_name} {l_name}')


# func4(*name)

################################################################
25 changes: 25 additions & 0 deletions 5-arb-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def func1(**details):
print(details, type(details))

for key, value in details.items():
print("{}: {}".format(key, value))


func1(Name="val_Name", Project="val_Project", Number="val_Number")

# func1(a=1, b=2)


################################################################


# def func2(*members, **features):
# for member in members:
# print(member)

# for key, value in features.items():
# print("{}: {}".format(key, value))


# func2("Bob", "Marley", Name="val_Name",
# Project="val_Project", Number="val_Number")
40 changes: 40 additions & 0 deletions 6-lambdas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import math


x = lambda a: a + 10
print(x(5))

x = lambda a, b: a * b
print(x(5, 6))


################################################################


# def emoji_factory(emoji):
# return lambda n: n * emoji


# bread_factory = emoji_factory('🍞')
# breads = bread_factory(5)
# print(breads)


################################################################


# def createLog(base):
# return lambda n: math.ceil(math.log(n, base))


# lg10 = createLog(10)
# lg2 = createLog(2)
# ln = createLog(math.e)

# print('lg10(100)', lg10(100))
# print('lg10(1000)', lg10(1000))

# print('lg2(8)', lg2(8))
# print('lg2(16)', lg2(16))

# print('ln(1)', ln(1))
49 changes: 49 additions & 0 deletions 7-doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from datetime import datetime


def greet(name):
"""
This function greets to
the person passed in as
a parameter
Parameters:
name(str): Name of user
Returns:
None
"""
print(f'Hello, {name}. How are you?')


# help(greet)
# print(greet.__doc__)
################################################################


# def say_time():
# '''
# Print current time
# :return: None
# '''
# print(datetime.now().strftime('%H:%M'))


# say_time()
# 'q' key for exit
# help(say_time)


################################################################


# def get_time():
# '''
# Generate time in HH:MM format
# :return: String
# '''
# return datetime.now().strftime('%H:%M')


# get_time()
# help(get_time)
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# **Functions**

## Links:
- https://www.programiz.com/python-programming/function
- https://www.educative.io/edpresso/what-are-keyword-arguments-in-python
- https://www.w3schools.com/python/python_functions.asp
- https://www.w3schools.com/python/python_lambda.asp
- https://www.datacamp.com/community/tutorials/docstrings-python

## Exercises:
- [1](https://www.w3schools.com/python/exercise.asp?filename=exercise_functions1)
- [Quiz](https://pynative.com/python-functions-quiz/)
- [2](https://pynative.com/python-functions-exercise-with-solutions/#h-exercise-1-create-a-function-in-python)
- [3](https://erlerobotics.gitbooks.io/erle-robotics-learning-python-gitbook-free/content/functions/exercises_functions.html)
- [Lambdas](https://www.w3schools.com/python/exercise.asp?filename=exercise_lambda1)
- [Only for teacher](http://hplgit.github.io/bumpy/doc/pub/sphinx-basics/._basics005.html#exercise-1-program-a-formula)
---
*24.01.2022 - Odesa*

0 comments on commit b0ca356

Please sign in to comment.