This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - break and continue | |
a = [0, 1, 2, 3, 4, 5] | |
print('-----------break for loop---------------------') | |
for x in a: | |
if x == 2: | |
break | |
print(x) | |
print('-----------continue for loop---------------------') | |
for x in a: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - Functions | |
def sum(arg1, arg2): | |
if type(arg1) != type(arg2): | |
print("Please give the args of same type") | |
return | |
return (arg1 + arg2) | |
a = sum(15, 60) | |
print(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - Default Arguments *args and **kwargs in Python | |
print('----Default Arguments----') | |
def studentExample1(name='unknown', age=0): | |
print("name: ", name) | |
print('age', age) | |
studentExample1() | |
studentExample1('tom') | |
studentExample1('tom', 22) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle: | |
pass | |
rect1 = Rectangle() | |
rect2 = Rectangle() | |
rect1.height = 20 | |
rect2.height = 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car: | |
pass | |
ford = Car() | |
honda = Car() | |
audi = Car() | |
ford.speed = 200 | |
honda.speed = 220 | |
audi.speed = 250 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car: | |
def __init__(self, speed, color): | |
print(speed) | |
print(color) | |
self.speed = speed | |
self.color = color | |
print('the __init__ is called') | |
ford = Car(200, 'red') | |
honda = Car(250, 'blue') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle: | |
def __init__(self, height, width): | |
self.height = height | |
self.width = width | |
rect1 = Rectangle(20, 60) | |
rect2 = Rectangle(50, 40) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle: | |
def __init__(self, height, width): | |
self.__height = height | |
self.__width = width | |
def set_height(self, height): | |
self.__height = height | |
def get_height(self): | |
return self.__height | |
def set_width(self, width): | |
self.__width = width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car: | |
def __init__(self, speed, color): | |
self.__speed = speed | |
self.__color = color | |
def set_speed(self, value): | |
self.__speed = value | |
def get_speed(self): | |
return self.__speed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hello: | |
def __init__(self, name): | |
self.public_variable = 10 | |
self.__private_variable = 30 | |
def public_method(self): | |
print(self.public_variable) | |
print(self.__private_variable) | |
print('public') | |
self.__private_method() |