diff --git a/README.md b/README.md new file mode 100644 index 0000000..aae445a --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Python-for-Beginners +Here you can find all the main Python files written throughout my free YouTube tutorial series Python for Beginners! +##Topics Covered : + +-> [if...elif...else](https://www.tutorialspoint.com/python/python_if_else.htm) + +-> [class and object](https://www.w3schools.com/python/python_classes.asp) + +-> [constructors](https://www.geeksforgeeks.org/constructors-in-python/) + +-> [file handling](https://www.tutorialspoint.com/python/python_files_io.htm) + +-> [functions](https://www.tutorialspoint.com/python/python_functions.htm) + +-> [loops](https://www.tutorialspoint.com/python/python_loops.htm) + +-> [modules](https://www.tutorialspoint.com/python/python_modules.htm) + +-----> [re module](https://www.w3schools.com/python/python_regex.asp) + +-> [tuples](https://www.tutorialspoint.com/python/python_tuples.htm) diff --git a/class.py b/class.py index c358896..2286207 100644 --- a/class.py +++ b/class.py @@ -1,6 +1,36 @@ -class Person: +#A simple program to under the concept of class and object in python3 +class BookStore: + noOfBooks = 0 + + def __init__(self, title, author): + self.title = title + self.author = author + BookStore.noOfBooks += 1 + + def bookInfo(self): + print("Book title:", self.title) + print("Book author:", self.author,"\n") + +# Create a virtual book store +b1 = BookStore("Great Expectations", "Charles Dickens") +b2 = BookStore("War and Peace", "Leo Tolstoy") +b3 = BookStore("Middlemarch", "George Eliot") + +# call member functions for each object +b1.bookInfo() +b2.bookInfo() +b3.bookInfo() - age = 18 +print("BookStore.noOfBooks:", BookStore.noOfBooks) - def name(self, name): - return list(name) +##OUTPUT : +#Book title: Great Expectations +#Book author: Charles Dickens + +#Book title: War and Peace +#Book author: Leo Tolstoy + +#Book title: Middlemarch +#Book author: George Eliot + +#BookStore.noOfBooks: 3 diff --git a/constructors.py b/constructors.py new file mode 100644 index 0000000..6e9c27e --- /dev/null +++ b/constructors.py @@ -0,0 +1,9 @@ + # Concept of constructor in python3 + class point(): + def __init__(self, x=0, y=0): + self.x = x + self.y = y + + p = point(10,20) # x = 10, y = 20 + p = point(10) # x = 10, y = 0 + p = point() # x = 0, y = 0 diff --git a/loops.py b/loops.py index 8441ac9..014be5c 100644 --- a/loops.py +++ b/loops.py @@ -1,16 +1,53 @@ - """ -# For loop -numbers = range(1,11) +### For loop +int_list = [1, 2, 3, 4, 5, 6] +sum = 0 +for iter in int_list: + sum += iter +print("Sum =", sum) +print("Avg =", sum/len(int_list)) -for number in numbers: - print(number) +##Output : +#Sum = 21 +#Avg = 3.5 """ -# While loop +""" +### Nested For loop +for x in range(1,5): + for y in range(1,5): + print(x*y) + +##Output : +#1 +#2 +#3 +#4 +#2 +#4 +#6 +#8 +#3 +#6 +#9 +#12 +#4 +#8 +#12 +#16 +""" -count = 0 +### While Loop +fruits = ["banana", "apple", "orange", "kiwi"] +position = 0 +while position < len(fruits): + print(fruits[position]) + position = position + 1 +print("reached end of list") -while count < 5: - print(count) - count += 1 +##Output : +#banana +#apple +#orange +#kiwi +#reached end of list