Skip to content

Update class.py #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
38 changes: 34 additions & 4 deletions class.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions constructors.py
Original file line number Diff line number Diff line change
@@ -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
57 changes: 47 additions & 10 deletions loops.py
Original file line number Diff line number Diff line change
@@ -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