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
# Linear Regression | |
# Model | |
from sklearn.linear_model import LinearRegression | |
reg=LinearRegression() | |
# Data | |
X=[[1], [2], [3], [4], [5], [6]] | |
Y=[2+1,4+1,6+1,8+1,10+1,12+1] |
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
s: set={1,2,3,4,5,55,5} | |
print(s) | |
# for loop | |
for i in s: | |
print(i) | |
# add, remove, clear, discard | |
s.add(33) | |
print(s) |
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
t: tuple=(1,2,3,4,5,5,5) | |
# for loop | |
for i in t: | |
print(i) | |
# immutable | |
# count | |
print(t.count(5)) |
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
l: list=[1,2,3,4,5] | |
# for loop | |
for i in l: | |
print(i) | |
# append | |
l.append(55) | |
print(l) |
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
# Parameter in definition, argument in function call | |
# No args + No return value | |
def printHello(): | |
print("Hello") | |
printHello() | |
# args + no return value | |
def printHelloWithName(name): | |
print("Hello",name) |
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
# print 1 to 10 | |
# using while loop | |
x=1 | |
while(x<=10): | |
print(x) | |
x+=1 | |
# using for loop | |
for i in range(1,11): |
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
# if elif else | |
x=15 | |
if(x>18): # Using circular brackets | |
print("Eligible to vote") | |
elif(x==18): | |
print("Just became eligible to vote") | |
elif x<=5: # Using space | |
print("You're a child") | |
else: |
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
# Arithmetic Operators & Assignment Operators | |
print( | |
5+3, | |
5-3, | |
5*3, | |
5/3, | |
5%3, | |
5**3, | |
5//3 | |
) |
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
name=input("Enter your name: ") | |
# input function by default takes string arguments | |
try: | |
x=input("Enter number to add with 5: ") | |
print(x+5) | |
except: | |
print("Error") | |
# What do you think happened? |
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
# Initializing a variable (declaration is done at the time of initialization) | |
x=5 | |
y="Hello World" | |
truthValue=True | |
# variableName = value | |
# Primitives: bool, int, float, complex, string | |
booleanVariableTrue=True |
NewerOlder